Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- void parse(const string& str, vector<vector<string>>& vResult)
- {
- map<string, int> mList;
- stringstream ss(str);
- string token;
- char delim = ' ';
- while (getline(ss, token, delim) && token[0] != '.')
- mList[token]++;
- using pair_type = decltype(mList)::value_type;
- int nMaxCount = max_element(mList.begin(), mList.end(),
- [](const pair_type& p1, const pair_type& p2)
- { return p1.second < p2.second; })->second;
- vResult.resize(nMaxCount + 1);
- for (const pair_type& item : mList)
- vResult[item.second].push_back(item.first);
- }
- int main()
- {
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- string szInput;
- getline(cin, szInput, '\n');
- vector<vector<string>> vResult;
- parse(szInput, vResult);
- size_t nQueries;
- cin >> nQueries;
- for (size_t i = 0; i < nQueries; ++i)
- {
- size_t nIndex, nCount;
- cin >> nIndex >> nCount;
- if (nIndex < vResult.size() && nCount < vResult[nIndex].size())
- cout << vResult[nIndex][nCount] << '\n';
- else
- cout << '.' << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment