Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Trello, Facil, Descubriendo nombres repetidos
- #include <iostream> /// AlenAntonelli
- #include <vector>
- #include <map>
- using namespace std;
- int main ()
- {
- int N, c=0;
- vector <pair <int, string>> may (3, {0,""});
- cin>>N; ///cin>>topFrecuentes;
- vector <string> nombres (N);
- cout<<"["<<N<<"]"<<endl;
- map <string, int> mapa;
- for (int i=0; i<N; i++)
- {
- cin>>nombres[i];
- mapa[ nombres[i] ]++; ///magic line
- }
- map <string, int>::iterator it= it=mapa.begin();
- for ( ; it!=mapa.end(); it++)
- {///cout<< (*it).first << " " << (*it).second << endl;
- if ((*it).second > may[0].first)
- {
- may[2].first=may[1].first;
- may[2].second=may[1].second;
- may[1].first=may[0].first;
- may[1].second=may[0].second;
- may[0].first = (*it).second;
- may[0].second = (*it).first;
- continue;
- }
- if ((*it).second > may[1].first)
- {
- may[2].first=may[1].first;
- may[2].second=may[1].second;
- may[1].first = (*it).second;
- may[1].second = (*it).first;
- continue;
- }
- if ((*it).second > may[2].first)
- {
- may[2].first = (*it).second;
- may[2].second = (*it).first;
- continue;
- }
- }
- for (int i=0; i<3; i++)
- cout<<may[i].second<<" "<<may[i].first<<endl;
- return may[0].first;
- }
Advertisement
Add Comment
Please, Sign In to add comment