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. C#日志写入

    /// <summary> /// 写日志,指定日志文件 /// </summary> /// <param name="File"></ ...

  2. DataTable或者DataRow转换对象

    public static IEnumerable<T> ConvertObject<T>(DataTable dt) where T : new() { var v = ty ...

  3. 【转载】为什么CPU有多层缓存

    原文:为什么CPU有多层缓存 http://mp.weixin.qq.com/s?__biz=MzI1NDM2Nzg5Mw==&mid=2247483712&idx=1&sn= ...

  4. Upgrade R (升级R语言)

    R R version 3.1.1 (2014-07-10) -- "Sock it to Me" yum list installed | grep R R-core.x86_6 ...

  5. ARM汇编编程概述

    1.为什么需要学些汇编指令 2.ARM汇编指令分类 3.汇编程序框架 4.编程准备 +++++++++++++++++++++++++++++++++++ 1.为什么需要学些汇编指令 bootload ...

  6. SQL 根据指定字符拆分字符串

    CREATE FUNCTION [dbo].[F_StringSplit] ( @STR NVARCHAR(MAX)='', )='') )) AS BEGIN DECLARE @NUM INT, @ ...

  7. windows下使用xShell远程连接virtualbox里面的linux

    第一阶段:基本安装 安装virtual box 在virtualbox里面安装xubuntu:是ubuntu+xfce桌面环境的一个linux的发行版本 在windows下安装Xmanager Ent ...

  8. 函数对象适配器之ptr_fun的使用示例

    //============================================================================ // Name : CopyInts4.c ...

  9. kafka单节点部署无法访问问题解决

    场景:在笔记本安装了一台虚拟机, 在本地的虚拟机上部署了一个kafka服务: 写了一个测试程序,在笔记本上运行测试程序,访问虚拟机上的kafka,报如下异常: 2015-01-15 09:33:26 ...

  10. iOS - UIDevice

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIDevice : NSObject @available(iOS 2.0, *) public class UI ...