Advertisement
Riposati

Winner codeforces

Jan 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie(NULL);
  9.  
  10.     map<string,int>mapa;
  11.     map<string,int>::iterator it;
  12.     int qtd,pontos,maximum=0;
  13.     string nomePessoa;
  14.  
  15.     cin>>qtd;
  16.  
  17.     for(int i=0;i<qtd;i++){
  18.  
  19.         cin>>nomePessoa>>pontos;
  20.         it = mapa.find(nomePessoa);
  21.  
  22.         if(it == mapa.end()){ // nao tem a pessoa ainda a registra
  23.             mapa.insert(make_pair(nomePessoa,pontos));
  24.  
  25.         }else{
  26.             it->second +=pontos;
  27.         }
  28.     }
  29.  
  30.     for (auto& x: mapa) {
  31.  
  32.         if(x.second > maximum){
  33.             nomePessoa = x.first;
  34.             maximum = x.second;
  35.         }
  36.         //cout << x.first << ": " << x.second << '\n';
  37.     }
  38.  
  39.     cout<<nomePessoa<<'\n';
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement