Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <map>
  4. #include <string>
  5. #include <vector>
  6. #include "query.h"
  7.  
  8. const int RESULTS_TO_PRINT = 3;
  9.  
  10. bool comp (std::pair<std::string, int>& a, std::pair<std::string, int>& b) {
  11. return (a.second > b.second);
  12. }
  13.  
  14. long long int min (long long int a, long long int b) {
  15. return ((a < b) ? a : b);
  16. }
  17.  
  18. int main() {
  19. size_t count = 0;
  20. std::map<std::string, int> login_stats;
  21. std::string line;
  22.  
  23. while (std::getline(std::cin, line)) {
  24. Query* q = parse_query(line.c_str());
  25.  
  26. if (q->action == ACTION_COMMIT) {
  27. login_stats[q->sender_login]++;
  28. }
  29.  
  30. delete q;
  31. }
  32.  
  33. std::vector<std::pair<std::string, int>> stats_vec(
  34. login_stats.begin(), login_stats.end());
  35. std::sort(stats_vec.begin(), stats_vec.end(), comp);
  36.  
  37. for (int i = 0; i < min(RESULTS_TO_PRINT, stats_vec.size()); ++i) {
  38. std::cout << stats_vec[i].first << " " << stats_vec[i].second << "\n";
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement