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.

Sample test(s)
Input
3
mike 3
andrew 5
mike 2
Output
andrew
Input
3
andrew 3
andrew 2
mike 5
Output
andrew

此题不大好懂,就是要你求出最大分数而且最先得到这个最高分的那个人的名字

思路: 第一步: 我们先求出所有人的最终得分
第二步: 我们求出最终得分的最高分:
第三部: 我们求出第一个得到最高分,而且最终得分也是最高分的那个人,那必定是最先出现的那个人..... 代码:
 #include<iostream>
#include<map>
using namespace std;
struct node
{
int score;
string name;
}ss[];
int main(){ string winner;
int n,maxsc;
map<string ,int>str;
//freopen("test.in","r",stdin);
while(cin>>n){
if(!str.empty()) str.clear();
for(int i=;i<n;i++){ //求出最终态势
cin>>ss[i].name>>ss[i].score;
str[ss[i].name]+=ss[i].score;
}
//求出最大的值
maxsc=str[ss[].name];
for(int i=;i<n;i++){
if(maxsc<str[ss[i].name]){
maxsc=str[ss[i].name];
}
}
map<string ,int>check; //这个表示过程态势
for(int i=;i<n;i++){
check[ss[i].name]+=ss[i].score;
if(check[ss[i].name]>=maxsc&&str[ss[i].name]>=maxsc){
winner=ss[i].name;
break;
}
}
cout<<winner<<endl;
}
return ;
}

cf------(round 2)A. Winner的更多相关文章

  1. CF Round #551 (Div. 2) D

    CF Round #551 (Div. 2) D 链接 https://codeforces.com/contest/1153/problem/D 思路 不考虑赋值和贪心,考虑排名. 设\(dp_i\ ...

  2. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

  3. UOJ #30. [CF Round #278] Tourists

    UOJ #30. [CF Round #278] Tourists 题目大意 : 有一张 \(n\) 个点, \(m\) 条边的无向图,每一个点有一个点权 \(a_i\) ,你需要支持两种操作,第一种 ...

  4. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  5. 【前行&赛时总结】◇第4站&赛时9◇ CF Round 513 Div1+Div2

    ◇第4站&赛时9◇ CF Round 513 Div1+Div2 第一次在CF里涨Rating QWQ 深感不易……作blog以记之 ( ̄▽ ̄)" +Codeforces 的门为你打 ...

  6. CF Round #600 (Div 2) 解题报告(A~E)

    CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include< ...

  7. CF Round #580(div2)题解报告

    CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...

  8. CF round #622 (div2)

    CF Round 622 div2 A.简单模拟 B.数学 题意: 某人A参加一个比赛,共n人参加,有两轮,给定这两轮的名次x,y,总排名记为两轮排名和x+y,此值越小名次越前,并且对于与A同分者而言 ...

  9. Codeforces Beta Round #2 A. Winner

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

  10. cf Round#273 Div.2

    题目链接,点击一下 Round#273 Div.2 ================== problem A Initial Bet ================== 很简单,打了两三场的cf第一 ...

随机推荐

  1. UVA 10817 十一 Headmaster's Headache

    Headmaster's Headache Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Sub ...

  2. Java获取音频文件(MP3)的播放时长

    最近的一个项目需要按照时间播放mp3文件,例如,播放10分钟的不同音乐. 这就意味着我得事先知道mp3文件的播放时长,以决定播放几遍这个文件. 方案一:Java的方式 找第三方的库,真的感谢这些提供j ...

  3. MySQL(六) —— 运算符和函数

    1. 字符函数   函数名称 描述 CONCAT()         字符连接                             CONCAT_WS()          使用指定的分隔符进行字 ...

  4. kaili 2.0 metasploit连接postgres数据库

    第一步:使用命令 db_init 初始化数据库

  5. javascript权威指南笔记--javascript语言核心(三)

    1.var用来声明一个或多个变量.全局变量是全局对象的属性,它无法通过delete删除. 如果var语句中的变量没有指定初始化表达式,那么这个变量的初始值为undefined. 变量声明语句会被提前到 ...

  6. 再学C++之C++中的全部关键字

    /*______C++全部关键字___________*/ asm do if return try auto double inline short typedef bool dynamic_cas ...

  7. FLASH CC 2015 CANVAS 导出音频问题

    1,导入音频无法成功发布(软件假死) 解决办法:先用个格式工厂重新压缩 在导入软件 发布 2, 音频 长度小于1秒(左右)的时候,导出后音频会变成  “哧”的一声,  估计和FLASH软件内部的音频编 ...

  8. JMS【四】--Spring和ActiveMQ整合的完整实例

    第一篇博文JMS[一]--JMS基本概念,我们介绍了JMS的两种消息模型:点对点和发布订阅模型,以及消息被消费的两个方式:同步和异步,JMS编程模型的对象,最后说了JMS的优点. 第二篇博文JMS[二 ...

  9. php获取在线xml的数据

    因为连接百度地图的API,然后通过经纬度得到位置信息,可是得到的位置信息是通过将经纬度嵌在url里面,生成xml文件后,因为是在线的,当时就想到在不下载的情况下获取里面的数据,因为使用代码下载是可以下 ...

  10. iOS - Swift NSCalendar 日历

    前言 public class NSCalendar : NSObject, NSCopying, NSSecureCoding NSCalendar 对世界上现存的常用的历法进行了封装,既提供了不同 ...