Winner

Winner

题面翻译

题目描述:

在 Berland 流行着纸牌游戏 Berlogging,这个游戏的赢家是根据以下规则确定的:

  1. 在每一轮中,玩家获得或失去一定数量的分数,在游戏过程中,分数被记录在 名称和得分 行中,其中名字是玩家的名字,得分是在这一轮中获得的分数。得分是负值意味着玩家失去了相应的分数。
  2. 如果在比赛结束时只有一名玩家分数最多,他就是获胜者。
  3. 如果两名或两名以上的玩家在比赛结束时都有最大的分数 m m m ,那么其中首先获得至少 m m m 分的玩家胜利。开始时,每个玩家都是 0 0 0 分。

保证在比赛结束时至少有一个玩家的分数为正。

【输入格式】

第一行包含整数 n n n,表示是游戏进行的的回合数。

2 ∼ n + 1 2 \sim n + 1 2n+1 行,按照时间顺序输入 名称和得分 行的信息,其中名称是长度不大于 32 32 32 的小写字母组成的字符串,分数的绝对值不大于 1000 1000 1000

【输出格式】

输出获胜者的名称。

题目描述

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.

输入格式

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.

输出格式

Print the name of the winner.

样例 #1

样例输入 #1

3
mike 3
andrew 5
mike 2

样例输出 #1

andrew

样例 #2

样例输入 #2

3
andrew 3
andrew 2
mike 5

样例输出 #2

andrew

思路

就是我们用map容器进行存储即可,第一次算的时候就先取出最大值,第二次算的时候看哪个人先到达最大值,他就是winner。具体来说也就是要开两个map。

代码

#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

const int N = 1010;

map<string,int>s,ss;
int n;
int k[N];
string a[N];

int main(){
    cin>>n;
    
    for(int i=1;i<=n;i++){
        cin>>a[i]>>k[i];
        s[a[i]]+=k[i];
    }
    
    int maxv=0;
    string ma;
    
    for(int i=1;i<=n;i++){
        maxv=max(maxv,s[a[i]]);
    }
    
    //重新模拟
    for(int i=1;i<=n;i++){
        ss[a[i]]+=k[i];
        
        if(s[a[i]]==maxv&&ss[a[i]]>=maxv){
            ma=a[i];
            break;
        }
    }
    
    cout<<ma;
    
    return 0;
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

green qwq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值