Advertisement
skb50bd

UVa 11577 Letter Frequency

Aug 28th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int T, i, max;
  7.     string line;
  8.     cin >> T;
  9.     while(T--) {
  10.         int Alpha[26] = {0};
  11.         cin.sync();
  12.         getline(cin, line);
  13.         for(i = 0; line[i]; i++) {
  14.             if(line[i] >= 65 && line[i] <= 91)
  15.                 Alpha[line[i] - 65]++;
  16.             else if(line[i] >= 97 && line[i] <= 122)
  17.                 Alpha[line[i] - 97]++;
  18.         }
  19.         for(i = 1, max = 0; i < 26; i++)
  20.             max = (Alpha[i] > Alpha[max]) ? i : max;
  21.         for(i = 0; i < 26; i++) {
  22.             char ch = i + 97;
  23.             if(Alpha[i] == Alpha[max]) cout << ch;
  24.         }
  25.         cout << endl;
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement