/
main
51 lines (40 loc) · 940 Bytes
/
main
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct stu {
char letter;
int times;
};
bool compare(const stu& a, const stu& b) {
return a.times > b.times || (a.times == b.times && a.letter < b.letter);
}
int main() {
struct stu table[26];
for(int i = 0; i < 26; i++) {
table[i].letter = 'A' + i;
table[i].times = 0;
}
string input;
string temp;
int teams;
cin >> teams;
//cin.ignore();
for(int i = 0; i < teams+1; i++) {
getline(cin, temp);
input = input + temp;
}
for(auto ch : input) {
int k = toupper(ch) - 'A';
if(k >= 0 && k < 26) {
table[k].times++;
}
}
sort(table, table + 26, compare);
for(int i = 0; i < 26; i++) {
if(table[i].times > 0) {
cout << table[i].letter << " " << table[i].times << endl;
}
}
return 0;
}