daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define getn int n; cin >> n
  6. #define fori(n) for (int i = 0; i < n; i++)
  7. #define forj(n) for (int j = 0; j < n; j++)
  8. #define forifill(n,x) for (int i = 0; i < n; i++) cin >> x[i]
  9. #define foriprint(n,x) for (int i = 0; i < n; i++) cout << x[i]
  10. #define all(x) x.begin(),x.end()
  11. #define inoutfile freopen("d:\\testcase.txt", "r", stdin);freopen("d:\\output.txt", "w", stdout)
  12.  
  13. bool sorting(pair<int, int> a, pair<int, int> b) {
  14.     if (a.second != b.second)
  15.         return a.second < b.second;
  16.     else
  17.         return a.first > b.first;
  18. }
  19.  
  20. int main() {
  21.     //inoutfile;
  22.     vector<pair<int, int>> freq(128);
  23.     fori(128) freq[i] = { i, 0 };
  24.     bool firsty = true;
  25.     string x;
  26.    
  27.     while (getline(cin, x)) {
  28.         if (!firsty) cout << endl; else firsty = false;
  29.  
  30.         fori(x.length()){
  31.             ++freq[x[i]].second;
  32.         }
  33.  
  34.         sort(all(freq), sorting);
  35.  
  36.         fori(128) {
  37.             if (freq[i].second != 0) cout << freq[i].first << " " << freq[i].second << endl;
  38.             freq[i] = { i, 0 };
  39.         }
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top