https://programmers.co.kr/learn/courses/30/lessons/17686#
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
bool compare(string s1, string s2) {
string tmp1, tmp2;
int n1, n2, i,k;
for (i = 0; i < s1.size() && !isdigit(s1[i]); i++) {
tmp1.push_back(tolower(s1[i]));
}
for (k = 0; k < s2.size() && !isdigit(s2[k]); k++) {
tmp2.push_back(tolower(s2[k]));
}
if (tmp1.compare(tmp2) != 0) {
return tmp1 < tmp2;
}
int n = 0;
tmp1.clear(); tmp2.clear();
for (; i < s1.size() && isdigit(s1[i]); i++,n++) {
if (n == 5) break;
tmp1.push_back(s1[i]);
}
for (n=0; k < s2.size() && isdigit(s2[k]); k++, n++) {
if (n == 5) break;
tmp2.push_back(s2[k]);
}
n1 = stoi(tmp1); n2 = stoi(tmp2);
if (n1 != n2) {
return n1 < n2;
}
else {
return false;
}
}
vector<string> solution(vector<string> files) {
stable_sort(files.begin(), files.end(), compare);
return files;
}
'전공공부 > 코딩테스트' 카테고리의 다른 글
(c++) 백준 "10163. 색종이" (0) | 2022.05.10 |
---|---|
(c++) 백준 "2578. 빙고" (0) | 2022.05.10 |
(c++) 백준 "2563. 색종이" (0) | 2022.05.04 |
(c++) 백준 "14696. 딱지놀이" (0) | 2022.05.03 |
(c++) 백준 "방 배정" (0) | 2022.05.03 |