File size: 998 Bytes
c4b0eef |
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 |
#include <algorithm>
#include <cctype>
#include <iostream>
#include <vector>
using namespace std;
struct wrap {
int count;
char alphabet;
bool operator<(const wrap& other) const {
if (count == other.count)
return alphabet < other.alphabet;
return count > other.count;
}
};
int main() {
int n, t, cnt;
char c;
vector<wrap> data(26);
while (cin >> n) {
cin.ignore(1024, '\n');
for (auto&& i : data)
i.count = 0;
for (int i = 0; i < n; i++) {
while ((c = cin.get()) != '\n') {
if (!isalpha(c))
continue;
cnt++;
t = toupper(c) - 65;
data[t].count++;
data[t].alphabet = toupper(c);
}
}
sort(data.begin(), data.end());
for (const auto& i : data) {
if (i.count)
cout << i.alphabet << " " << i.count << "\n";
}
}
} |