SHARE
TWEET

Untitled

a guest Jun 16th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. bool compare (pair<int, string> a, pair<int, string> b)
  10. {
  11.      if (a.first != b.first) {
  12.        return (a.first > b.first);
  13.      } else {
  14.        return lexicographical_compare(a.second.begin(), a.second.end(), b.second.begin(), b.second.end());
  15.      }
  16. }
  17.  
  18. int main()
  19. {
  20.     string z;
  21.     map<string, int> array;
  22.     while(cin >> z){
  23.         if(array.count(z) == 0){
  24.      array[z] = 1;
  25.         }
  26.     else{
  27.         array[z]++;
  28.     }
  29.     }
  30.  
  31.     //for (auto el: array) {
  32.     //    cout << el.first << " " << el.second << endl;
  33.     //}
  34.     vector<pair<int,string>> a;
  35.     for(auto el: array){
  36.         pair<int, string> tmp;
  37.         tmp.first = el.second;
  38.         tmp.second = el.first;
  39.         a.push_back(tmp);
  40.     }
  41.  
  42.     //for (auto el: a) {
  43.     //    cout << el.second << " " << el.first << endl;
  44.     //}
  45.  
  46.     sort(a.begin(), a.end(), compare);
  47.     for(auto el: a){
  48.         cout << el.second << endl;
  49.     }
  50.     return 0;
  51. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top