Advertisement
FuFsQ

balls_task

Sep 23rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. inline void split_vec(std::vector< pair<int,std::string> > &Expressions, std::string &str){
  10.     unsigned int str_sz = str.size();
  11.     unordered_map<std::string,int> EX;
  12.  
  13.     if(str.size() > 0){
  14.         std::string Buffer = "";
  15.         for(auto &I : str)
  16.         {
  17.             if(I != ' '){
  18.                 Buffer += I;
  19.             }else{
  20.                 EX[Buffer]++;
  21.                 Buffer.clear();
  22.             }
  23.         }
  24.         EX[Buffer]++;
  25.     }
  26.  
  27.     for(auto &I : EX)
  28.         Expressions.emplace_back(I.second,I.first);
  29. }
  30.  
  31. int main()
  32. {
  33.     std::string inp;
  34.     getline(cin, inp);
  35.  
  36.     vector< pair<int,std::string> > E;
  37.     split_vec(E,inp);
  38.     sort(E.begin(),E.end());
  39.  
  40.     vector< vector< pair<std::string,int> > > Sorted;
  41.     vector<         pair<std::string,int> >    Buff;
  42.  
  43.     int GroupKey = E[0].first;
  44.  
  45.     for(auto &I : E){
  46.         if(GroupKey == I.first){
  47.             Buff.emplace_back(I.second,I.first);
  48.         }else{
  49.             GroupKey = I.first;
  50.             Sorted.emplace_back(Buff);
  51.             Buff.clear();
  52.  
  53.             Buff.emplace_back(I.second,I.first);
  54.         }
  55.     }
  56.     Sorted.emplace_back(Buff);
  57.  
  58.     for(auto &I : Sorted)
  59.         sort(I.begin(),I.end());
  60.  
  61.  
  62.     for(int I = Sorted.size()-1; I >= 0; I--)
  63.         for(auto &K : Sorted[I])
  64.             cout << K.first << endl;
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement