Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions khj20006/202511/18 PGM LV2 파일명 정렬.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
```cpp
#include <bits/stdc++.h>
using namespace std;

class CustomString {
public:
string str, head;
int number, order;
CustomString(string a, int ord) {
this->str = a;
this->order = ord;
int idx = 0;
this->head = "";
string num = "";
while (idx < a.size()) {
if ('0' <= a[idx] && a[idx] <= '9') {
num += a[idx];
}
else {
if (!num.empty()) break;
if ('A' <= a[idx] && a[idx] <= 'Z') head += (char)(a[idx] + 32);
else head += a[idx];
}
idx++;
}
this->number = stoi(num);
}
};


vector<string> solution(vector<string> files) {
vector<CustomString*> customFiles;
int ord = 0;
for (string file : files) {
customFiles.push_back(new CustomString(file, ++ord));
}

sort(customFiles.begin(), customFiles.end(), [](CustomString* a, CustomString* b) -> bool {
if (a->head != b->head) return a->head < b->head;
if (a->number != b->number) return a->number < b->number;
return a->order < b->order;
});

vector<string> answer;
for (CustomString* cs : customFiles) {
answer.push_back(cs->str);
}

return answer;
}
```