-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1431.cpp
More file actions
60 lines (52 loc) · 1.06 KB
/
BOJ1431.cpp
File metadata and controls
60 lines (52 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
나는 빠가다 나는 빠가다...
비교식에서 어떻게 저런식으로 짤수 있지;;
1. 비교식 부분에서 잘못 판단한게 크다 ...
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define N 1000001
using namespace std;
int n;
vector<string> v;
int cmpSum(string s){
int ret=0;
for(auto a:s){
if('0'<=a&&a<='9')
ret+=a-'0';
}
return ret;
}
bool cmp(string s1,string s2){
if(s1.length()==s2.length())
{
if(cmpSum(s1)==cmpSum(s2))
return s1<s2;
else
return cmpSum(s1)<cmpSum(s2);
}
else
return s1.length()<s2.length();
// if(s1.length()<s2.length())
// return true;
// else if(cmpSum(s1)<cmpSum(s2))
// return true;
// else
// return s1<s2;
// return false;
}
int main(){
cin>>n;
while(n--){
string s;
cin>>s;
v.push_back(s);
}
sort(v.begin(),v.end(),cmp);
for(auto a:v)
cout<<a<<endl;
return 0;
}