-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_homework.cpp
68 lines (55 loc) · 1.26 KB
/
math_homework.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
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int main() {
int N;
string S;
string tmp = "";
vector <pair<int, string>> v;
bool check = false, count = false;
scanf("%d", &N);
tmp = "";
for (int i = 0; i < N; i++) {
cin >> S;
for (int k = 0;k < S.length();k++) {
if (isdigit(S[k])) {
if (S[k] == '0' && (!(check))) { //앞자리 0인거 구별 하기 위해서.
count = true;
if (k == S.length() - 1 && !(check)) {
v.push_back(make_pair(1,"0"));
count = false;
}
continue;
}
tmp += S[k];
check = true;
count = false;
if (k == S.length()-1 && check ) { //맨 마지막인 경우
v.push_back(make_pair(tmp.length(),tmp));
tmp = "";
check = false;
count = false;
}
}
else {
if (check) { //숫자 넣기.
v.push_back(make_pair(tmp.length(),tmp));
tmp = "";
}
else if (count && tmp.length() == 0) { //전부 0인경우
v.push_back(make_pair(1,"0"));
count = false;
}
check = false;
}
}
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i].second << '\n';
}
}