File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ // https://school.programmers.co.kr/learn/courses/30/lessons/17686
2+
3+ #include < string>
4+ #include < vector>
5+ #include < iostream>
6+ #include < algorithm>
7+
8+ using namespace std ;
9+
10+ struct File {
11+ int idx;
12+ string head;
13+ int number;
14+ };
15+
16+ struct cmp {
17+ bool operator ()(const File &f1, const File &f2) {
18+ if (f1.head != f2.head ) return f1.head < f2.head ;
19+ else if (f1.number != f2.number ) return f1.number < f2.number ;
20+ else return f1.idx < f2.idx ;
21+ }
22+ };
23+
24+ vector<File> v;
25+
26+ vector<string> solution (vector<string> files) {
27+ vector<string> answer;
28+
29+ for (int i = 0 ; i < files.size (); i++) {
30+ string head = " " ;
31+ int idx = 0 ;
32+ for (int j = 0 ; j < files[i].size (); j++){
33+ if (' 0' <= files[i][j] && files[i][j] <= ' 9' ) {
34+ idx = j;
35+ break ;
36+ }
37+ head += tolower (files[i][j]);
38+ }
39+
40+ string number = " " ;
41+ for (int j = idx; j < files.size (); j++){
42+ if (!(' 0' <= files[i][j] && files[i][j] <= ' 9' )) {
43+ idx = j;
44+ break ;
45+ }
46+ number += files[i][j];
47+ }
48+
49+ File f;
50+ f.idx = i;
51+ f.head = head;
52+ f.number = stoi (number);
53+
54+ v.push_back (f);
55+ }
56+
57+ sort (v.begin (), v.end (), cmp ());
58+
59+ for (int i = 0 ; i < v.size (); i++){
60+ answer.push_back (files[v[i].idx ]);
61+ }
62+
63+ return answer;
64+ }
You can’t perform that action at this time.
0 commit comments