Title Link: Http://codeforces.com/problemset/problem/2/A
A. winnertime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard output
The winner of the card game popular in Berland "berlogging" are determined according to the following rules. If at the end of the game there are only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players are more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points are registered in the line "Name Score", wherenameis a player ' s name, andscoreIs the number of points gained in this round, which is an integer number. IF score is negative, this means the player has lost in the round. So, if both or more players has the maximum number of points (say, it equals tom) at the end of the game, than wins the oneof themWho scored at leastmPoints first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player have a positive number of points.
Input
The first line contains an integer numberN(1?? ≤?? n?? ≤?? +),NIs the number of rounds played. Then followNLines, containing the information about the rounds in "Name Score"Format in chronological order, wherenameis a string of lower-case Latin letters with the length from 1 toscoreis an integer number between-1000 and inclusive.
Output
Print the name of the winner.
Sample Test (s) input
3mike 3andrew 5mike 2
Output
Andrew
Input
3andrew 3andrew 2mike 5
Output
Andrew
Test instructions
Give the names and fractions of some columns! Positive means add points, negative means minus points! The name of the person with the greatest final score;
If the person with the highest score has more than one, output the person who first reaches the maximum score!
The code is as follows:
#include <cstdio> #include <iostream> #include <map>using namespace std;map<string, int> A, B; String S[1017];int Main () { int x[1017]; int n; CIN >> N; for (int i = 1; I <= n; i++) { cin >> s[i] >> x[i]; A[s[i]]+=x[i]; } int maxx = 0; for (int i = 1; I <= n; i++) { if (A[s[i]] > Maxx) maxx = A[s[i]]; } for (int i = 1; I <= n; i++) { b[s[i]]+=x[i]; if ((B[s[i]]>=maxx) && (A[s[i]]>=maxx))//In the final score is the largest of the people, select the first to reach the maximum score of the person { cout << s[i]; break; } } return 0;}
Codeforces 2a-winner (Analog)