Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. string str;
  6. int n,i , j;
  7. int score;
  8. int mx = 0;
  9. string k;
  10. map <string , int > my_map;
  11. map<string , int > :: iterator it;
  12. scanf("%d", &n);
  13.  
  14. for(i = 0; i<n; i++) {
  15. cin>> str;
  16. cin>> score;
  17.  
  18. it = my_map.find(str);
  19.  
  20. if(it == my_map.end()) {
  21.  
  22. my_map[str] = score;
  23. if(score > mx) {
  24. mx = score;
  25. k = str;
  26. }
  27. }
  28. else{
  29. int l = my_map[str];
  30. l+= score;
  31. my_map[str] = l;
  32.  
  33. if(l > mx) {
  34. mx = l;
  35. k = str;
  36. }
  37.  
  38. }
  39. }
  40.  
  41. /* for(it = my_map.begin(); it != my_map.end(); it++) {
  42. cout << it->first << " " << it->second<< endl;
  43. }*/
  44. cout << k <<endl;
  45.  
  46. return 0;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement