Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- #include <vector>
- using namespace std;
- int main ()
- {
- string input;
- getline (cin, input);
- map <string, int> words;
- int index = input.find (" ");
- string result = input.substr (0, index);
- words.insert (pair <string, int> {result, 1});
- while (index != string::npos)
- {
- int tempIndex = input.find (" ", index + 1);
- result = input.substr(index + 1, tempIndex - (index + 1));
- if (words.find (result) == words.end())
- {
- words.insert (pair <string, int> {result, 1});
- } else
- {
- words[result]++;
- }
- index = tempIndex;
- }
- int queries;
- cin >> queries;
- vector <string> results;
- for (int i = 0; i < queries; ++i)
- {
- int occurency;
- int position;
- cin >> occurency >> position;
- set <string> tempWords;
- map <string, int>::iterator it = words.begin();
- for (it; it != words.end();)
- {
- if (it -> second == occurency)
- {
- tempWords.insert(it->first);
- }
- it++;
- if (it == words.end())
- {
- if (tempWords.empty() || position >= tempWords.size())
- {
- cout << "." << endl;
- } else
- {
- set <string>::iterator itSet = tempWords.begin();
- int counter = 0;
- for (itSet; itSet != tempWords.end(); ++itSet)
- {
- if (counter == position)
- {
- results.push_back (*itSet);
- break;
- }
- counter ++;
- }
- counter = 0;
- }
- }
- }
- }
- for (int i = 0; i < results.size(); i++)
- {
- cout << results[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement