-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSolution.cpp
37 lines (32 loc) · 893 Bytes
/
Solution.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
33
34
35
36
37
#include <string>
#include <unistd.h>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
int cnt[26][26];
class Solution {
public:
string rankTeams(vector<string>& votes) {
string res = votes[0];
const int n = votes[0].size();
vector<vector<int>> rank (26, vector <int> (n, 0));
for (auto str : votes)
for (int i=0; i<str.size(); i++)
rank[str[i]-'A'][i] ++ ;
auto cmp = [&] (const char & a, const char & b) -> bool {
for (int i=0; i<n; )
if (rank[a-'A'][i] == rank[b-'A'][i]) i ++ ;
else return rank[a-'A'][i] > rank[b-'A'][i];
return a < b;
};
sort(res.begin(), res.end(), cmp);
return res;
}
};
int main() {
Solution s;
cout << sizeof(cnt);
return 0;
}