링크 : https://www.acmicpc.net/problem/1431
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
bool comp(string a, string b){
if (a.size() == b.size()){
int sum1 = 0, sum2 = 0;
for(int i = 0; i < a.size(); i++){
if(isdigit(a[i]) != 0){
int tmp = a[i] - '0';
sum1 += tmp;
}
if(isdigit(b[i]) != 0){
int tmp = b[i] - '0';
sum2 += tmp;
}
}
if(sum1 != sum2) return sum1 < sum2;
else return a < b;
}
else return a.size() < b.size();
}
vector<string> v;
int main(){
int N = 0;
cin >> N;
vector<string> v;
for(int i = 0; i < N; i++){
string temp = "";
cin >> temp;
v.push_back(temp);
}
sort(v.begin(), v.end(), comp);
for(string s : v){
cout << s << "\n";
}
return 0;
}