1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <bits/stdc++.h> using namespace std; struct round{ string name; int score; }; map<string,int>NameToScore; vector<struct round>AllRounds; set<string>Potential; int main() { //Logic : See, who has the maximum points in the final round He is the winner //If there are multiple such contestant then the winner -> who had a better //or equal to that score in the most previous round int N; cin>>N; //How to simulate each round after I have taken all input -> save it for(int a = 0;a<N;a++) { string s ; int scr ; cin>>s>>scr; struct round dummyRound; dummyRound.name = s; dummyRound.score = scr; AllRounds.push_back(dummyRound); NameToScore[s]+=scr; } int mx = -10000000; for(map<string,int>::iterator it = NameToScore.begin();it!=NameToScore.end();it++) { if( it->second > mx ) { mx = it->second; } } for(map<string,int>::iterator it = NameToScore.begin();it!=NameToScore.end();it++) { if( it->second == mx ) //All potential contestant { Potential.insert(it->first); } } //All rounds check NameToScore.clear(); for(int a = 0;a<N;a++) { struct round RoundSimulate = AllRounds[a]; string nm = RoundSimulate.name; int score = RoundSimulate.score; NameToScore[nm]+= score; set<string>::iterator setIt; setIt = Potential.find(nm); if(NameToScore[nm] >= mx && setIt!=Potential.end()) { cout<<nm<<endl; break; } } return 0; } |
Saturday, January 30, 2016
T 1 ) 2 A Winner
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment