Skip to content

Commit 17b9d16

Browse files
authored
[20251118] PGM / LV2 / 파일명 정렬 / 권혁준
1 parent 2bdcc6b commit 17b9d16

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
class CustomString {
6+
public:
7+
string str, head;
8+
int number, order;
9+
CustomString(string a, int ord) {
10+
this->str = a;
11+
this->order = ord;
12+
int idx = 0;
13+
this->head = "";
14+
string num = "";
15+
while (idx < a.size()) {
16+
if ('0' <= a[idx] && a[idx] <= '9') {
17+
num += a[idx];
18+
}
19+
else {
20+
if (!num.empty()) break;
21+
if ('A' <= a[idx] && a[idx] <= 'Z') head += (char)(a[idx] + 32);
22+
else head += a[idx];
23+
}
24+
idx++;
25+
}
26+
this->number = stoi(num);
27+
}
28+
};
29+
30+
31+
vector<string> solution(vector<string> files) {
32+
vector<CustomString*> customFiles;
33+
int ord = 0;
34+
for (string file : files) {
35+
customFiles.push_back(new CustomString(file, ++ord));
36+
}
37+
38+
sort(customFiles.begin(), customFiles.end(), [](CustomString* a, CustomString* b) -> bool {
39+
if (a->head != b->head) return a->head < b->head;
40+
if (a->number != b->number) return a->number < b->number;
41+
return a->order < b->order;
42+
});
43+
44+
vector<string> answer;
45+
for (CustomString* cs : customFiles) {
46+
answer.push_back(cs->str);
47+
}
48+
49+
return answer;
50+
}
51+
```

0 commit comments

Comments
 (0)