codeforces 2A Winner

A. Winner
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is 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 is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.

Input

The first line contains an integer number n (1  ≤  n  ≤  1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.

Output

Print the name of the winner.

Examples
input
Copy
3
mike 3
andrew 5
mike 2
output
andrew
input
Copy
3
andrew 3
andrew 2
mike 5
output

andrew


题目的大意:几个人在玩一个游戏,初始的分数都是0,每回合由某人给出一个分数(可以为负),负的话总分就减去这个数,求游戏结束时分数最高的人的名字,如果有几个人的总分相同的话,就输出最先到达这个分数的男人(可以高于这个最终总分)。


#include <bits/stdc++.h>
int maxn=-1e7;
using namespace std;
struct Gamer
{
	string name;
	int score;
}a[1002];
int main()
{
	int n;
	cin>>n;
	map<string,int>b;
	map<string,int>c;
	for(int p=0; p<n; p++)
	{
		cin>>a[p].name>>a[p].score;
		b[a[p].name]+=a[p].score;
	}
    for(auto i: b)
    {
    	if(maxn<i.second)
    	maxn=i.second;
	}
	string ans;
	int j;
	for(j=0; j<n; j++)      
	{
		c[a[j].name]+=a[j].score;
		if(c[a[j].name]>=maxn && b[a[j].name]==maxn) //这里傻了,开始时写了两个等来判断,其实是可以高于最终总分的 
		{
			ans=a[j].name;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
} 
/*
给一组数据:
15
aawtvezfntstrcpgbzjbf 681          681
zhahpvqiptvksnbjkdvmknb -74        -74
aawtvezfntstrcpgbzjbf 661          1342
jpdwmyke 474                       474
aawtvezfntstrcpgbzjbf -547         795  
aawtvezfntstrcpgbzjbf 600          1395
zhahpvqiptvksnbjkdvmknb -11        -85
jpdwmyke 711                       1185
bjmj 652                           652
aawtvezfntstrcpgbzjbf -1000        395
aawtvezfntstrcpgbzjbf -171         224
bjmj -302                          350
aawtvezfntstrcpgbzjbf 961          1185
zhahpvqiptvksnbjkdvmknb 848        763
bjmj -735                          -1085
 
*/ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值