Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- #include "query.h"
- using namespace std;
- bool compare(const pair<string,int> &first, const pair<string,int> &second)
- {
- return (first.second > second.second);
- }
- int main()
- {
- int RESULTS_TO_PRINT = 0;
- bool find;
- map<string, int> loginStats;
- string line;
- while (getline(cin, line))
- {
- Query* q = parseQuery(line.c_str());
- if (q->action == ACTION_COMMIT)
- {
- find = false;
- for (auto it = loginStats.begin(); it != loginStats.end(); it++) {
- if (it->first == q->sender_login) {
- it->second++;
- find = true;
- break;
- }
- }
- if (!find) {
- loginStats.insert(pair<string, int>(q->sender_login, 1));
- }
- delete [] q;
- }
- if(loginStats.size() >= 3){
- RESULTS_TO_PRINT = 3;
- }
- else {
- RESULTS_TO_PRINT = loginStats.size();
- }
- }
- vector<pair<string, int> >
- statsVec(loginStats.begin(), loginStats.end());
- sort(statsVec.begin(), statsVec.end(), compare);
- for (int i = 0; i < RESULTS_TO_PRINT; ++i)
- {
- cout << statsVec[i].first << " " << statsVec[i].second << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement