-
Notifications
You must be signed in to change notification settings - Fork 481
/
0937.cpp
32 lines (30 loc) · 829 Bytes
/
0937.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
vector<string> reorderLogFiles(vector<string>& logs)
{
stable_sort(logs.begin(), logs.end(), cmp);
return logs;
}
private:
static bool cmp(const string &A, const string& B)
{
string subA = A.substr(A.find(' ') + 1);
string subB = B.substr(B.find(' ') + 1);
if (isdigit(subA[0])) return false;
else if (isdigit(subB[0])) return true;
return subA.compare(subB) < 0;
}
};
int main()
{
vector<string> logs = {"a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"};
cout << Solution().reorderLogFiles(logs);
return 0;
}