-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ_1431.cpp
60 lines (52 loc) · 1.08 KB
/
BOJ_1431.cpp
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
// 백준 1431 시리얼 번호
// 21.02.08
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#define INF 2147000000
typedef long long ll;
using namespace std;
bool compare(string a, string b)
{
if (a.length() == b.length())
{
int sumA = 0, sumB = 0;
for (int i = 0; i < a.length(); ++i)
{
if (a[i] >= '0' && a[i] <= '9')
{
sumA += a[i] - '0';
}
}
for (int i = 0; i < b.length(); ++i)
{
if (b[i] >= '0' && b[i] <= '9')
{
sumB += b[i] - '0';
}
}
if (sumA == sumB)
{
return a < b;
}
else return sumA < sumB;
}
else return a.length() < b.length();
}
int main()
{
int n; cin >> n;
vector <string> v;
for (int i = 0; i < n; ++i)
{
string s; cin >> s;
v.push_back(s);
}
sort(v.begin(), v.end(), compare);
for (int i = 0; i < n; ++i)
cout << v[i] << "\n";
return 0;
}