Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 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. int main() {
  11. std::map<std::string, int> login_stats;
  12. std::string line;
  13. while (std::getline(std::cin, line)) {
  14. Query* q = new Query;
  15. q = parse_query(line.c_str());
  16. if (q->action == ACTION_COMMIT) {
  17. ++login_stats[q->sender_login];
  18. }
  19. delete q;
  20. }
  21.  
  22. std::vector<std::pair<std::string, int>> stats_vec(
  23. login_stats.begin(), login_stats.end());
  24. std::sort(stats_vec.begin(), stats_vec.end(), [](
  25. const std::pair<std::string, int> &a,
  26. const std::pair<std::string, int> &b) { return a.second > b.second;});
  27. if (stats_vec.size() < 3) {
  28. for (size_t i = 0; i < stats_vec.size(); ++i)
  29. std::cout << stats_vec[i].first << " "<< stats_vec[i].second << "\n";
  30. } else {
  31. for (int i = 0; i < RESULTS_TO_PRINT; ++i)
  32. std::cout << stats_vec[i].first << " " << stats_vec[i].second << "\n";
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement