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"
- const int RESULTS_TO_PRINT = 3;
- bool comp (std::pair<std::string, int>& a, std::pair<std::string, int>& b) {
- return (a.second > b.second);
- }
- long long int min (long long int a, long long int b) {
- return ((a < b) ? a : b);
- }
- int main() {
- size_t count = 0;
- std::map<std::string, int> login_stats;
- std::string line;
- while (std::getline(std::cin, line)) {
- Query* q = parse_query(line.c_str());
- if (q->action == ACTION_COMMIT) {
- login_stats[q->sender_login]++;
- }
- delete q;
- }
- std::vector<std::pair<std::string, int>> stats_vec(
- login_stats.begin(), login_stats.end());
- std::sort(stats_vec.begin(), stats_vec.end(), comp);
- for (int i = 0; i < min(RESULTS_TO_PRINT, stats_vec.size()); ++i) {
- std::cout << stats_vec[i].first << " " << stats_vec[i].second << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement