JuliaMelkozerova

HW3A

Oct 17th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int i = 0;
  11.     vector <pair<int, char>> L(26);
  12.     for (i = 0; i < 26; i++) L[i].first = 0;
  13.     for (i = 0; i < 26; i++) L[i].second = (char)((int)'A' + i);
  14.  
  15.     char c;
  16.     for (int c = getchar(); c != EOF; c = getchar()) {
  17.         if ((c >= 'A') && (c <= 'Z')) L[(int)(c)-(int)('A')].first++;
  18.     }
  19.  
  20.     sort(L.begin(), L.end(), [](pair<int, char> a, pair<int, char> b) {return a.first > b.first; });
  21.     for (i = 0; i < 26; i++) if (L[i].first) cout << L[i].second << ' ' << L[i].first << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment