AlenAntonelli

Descubriendo nombres repetidos

May 20th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. //* Alen Antonelli 2018*/ https://trello.com/c/zq0mLpqv/64-2007n2p1-descubriendo-nombres-repetidos
  2. #include <iostream>
  3. #include <map>
  4. using namespace std;
  5. int main()
  6. {
  7.     map<string, int> mapa;
  8.     map<int, string> id;
  9.    
  10.     int N, K;
  11.     cin>>N>>K;
  12.     for (int i=0; i<N; i++)
  13.     {
  14.         string nombre;
  15.         cin>>nombre;
  16.         mapa[nombre]++;
  17.     }
  18.    
  19.     for (auto i:mapa) ///auto i rules!!!
  20.         id[i.second]=i.first;
  21.    
  22.     map<int,string>::reverse_iterator it = id.rbegin();
  23.     for (int i=0; i<K; i++, ++it) ///nada mas lindo que romper la singaxis habitual del for :)
  24.         cout<<it->first<<" "<<it->second<<endl;
  25.    
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment