Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //* Alen Antonelli 2018*/ https://trello.com/c/zq0mLpqv/64-2007n2p1-descubriendo-nombres-repetidos
- #include <iostream>
- #include <map>
- using namespace std;
- int main()
- {
- map<string, int> mapa;
- map<int, string> id;
- int N, K;
- cin>>N>>K;
- for (int i=0; i<N; i++)
- {
- string nombre;
- cin>>nombre;
- mapa[nombre]++;
- }
- for (auto i:mapa) ///auto i rules!!!
- id[i.second]=i.first;
- map<int,string>::reverse_iterator it = id.rbegin();
- for (int i=0; i<K; i++, ++it) ///nada mas lindo que romper la singaxis habitual del for :)
- cout<<it->first<<" "<<it->second<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment