-
Notifications
You must be signed in to change notification settings - Fork 0
/
napor.cpp
70 lines (58 loc) · 1.28 KB
/
napor.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
61
62
63
64
65
66
67
68
69
70
// https://www.acmicpc.net/problem/2870
#include <bits/stdc++.h>
using namespace std;
bool cmp(string&, string&);
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<string> res;
while (n--) {
string str;
cin>>str;
string tmp;
for (char& c : str) {
if (isdigit(c)) {
tmp+=c;
}
else {
if (tmp.empty()) {
continue;
}
while (tmp.front()=='0' && tmp.size()>1) {
tmp.erase(0,1);
}
res.push_back(tmp);
tmp.clear();
}
}
if (!tmp.empty()) {
while (tmp.front()=='0' && tmp.size()>1) {
tmp.erase(0,1);
}
res.push_back(tmp);
tmp.clear();
}
}
sort(res.begin(),res.end(),cmp);
for (string& str : res) {
cout << str << '\n';
}
return 0;
}
bool cmp(string& a, string& b)
{
if (a.size()!=b.size()) {
return a.size()<b.size();
}
int n = a.size();
for (int i = 0; i<n; ++i) {
if (a[i]==b[i]) {
continue;
}
return a[i]<b[i];
}
return true;
}