1
class Solution {
2
public:
3
static bool comp(pair<string, string> a, pair<string, string> b) {
4
if (a.second == b.second) return a.first < b.first;
5
return a.second < b.second;
6
}
7
vector<string> reorderLogFiles(vector<string> &logs) {
8
vector<pair<string, string>> letter_logs;
9
vector<string> digit_logs;
10
vector<string> ans;
11
for (int i = 0; i < logs.size(); i++) {
12
string identifier = "";
13
for (int j = 0; j < logs[i].length(); j++) {
14
if (logs[i][j] == ' ') {
15
if (logs[i][j + 1] >= 'a' && logs[i][j + 1] <= 'z')
16
letter_logs.push_back({identifier, logs[i].substr(j + 1, logs[i].size() - j + 1)});
17
else
18
digit_logs.push_back(logs[i]);
19
break;
20
} else {
21
identifier.push_back(logs[i][j]);
22
}
23
}
24
}
25
sort(letter_logs.begin(), letter_logs.end(), comp);
26
for (auto it : letter_logs) {
27
cout << it.first + " " + it.second << endl;
28
ans.push_back(it.first + " " + it.second);
29
}
30
for (auto it : digit_logs) {
31
cout << it << endl;
32
ans.push_back(it);
33
}
34
return ans;
35
}
36
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0