Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int C, N;
- cin >> C >> N;
- map<string, int> nombres;
- string aux;
- for(int i = 0; i < C; i++)
- {
- cin >> aux;
- nombres[aux]++;
- }
- vector<int> cantidades; // Las veces que aparece X palabra
- for(auto e : nombres)
- {
- cantidades.push_back(e.second);
- }
- sort(cantidades.begin(), cantidades.end(), greater<int>());
- cantidades.resize(N);
- for(auto e : nombres)
- {
- if(find(cantidades.begin(), cantidades.end(), e.second) != cantidades.end())
- {
- cout << e.first << " " << e.second << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement