Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int i = 0;
- vector <pair<int, char>> L(26);
- for (i = 0; i < 26; i++) L[i].first = 0;
- for (i = 0; i < 26; i++) L[i].second = (char)((int)'A' + i);
- char c;
- for (int c = getchar(); c != EOF; c = getchar()) {
- if ((c >= 'A') && (c <= 'Z')) L[(int)(c)-(int)('A')].first++;
- }
- sort(L.begin(), L.end(), [](pair<int, char> a, pair<int, char> b) {return a.first > b.first; });
- for (i = 0; i < 26; i++) if (L[i].first) cout << L[i].second << ' ' << L[i].first << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment