Winner

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

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 Input

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;
const int maxx=;
struct Node
{
string name;
int grade;
} stu[maxx];
int main()
{
int n;
string ans="";
scanf("%d",&n);
string name;
int max=;
map<string,int>m;
for(int i=; i<n; i++)
{
string name;
int a;
cin>>name>>a;
stu[i].name=name;
stu[i].grade=a;
if(m.count(name))
m[name]+=a;
else
{
m.insert(pair<string,int>(name,a));
}
}
map<string,int>nm;
map<string,int>::iterator iter;
for(iter=m.begin(); iter!=m.end(); iter++)
{
// cout<<iter->first<<" "<<iter->second<<endl;
if(iter->second>max)
{
nm.clear();
nm.insert(pair<string,int>(iter->first,)); max=iter->second;
}
else if(iter->second==max)
{
nm.insert(pair<string,int>(iter->first,));
}
}
m.clear();
//cout<<max;
for(int i=; i<n; i++)
{
if(m.count(stu[i].name))
{
m[stu[i].name]+=stu[i].grade;
if((m[stu[i].name]>=max)&&(nm.count(stu[i].name)))
{
ans=stu[i].name;
break;
}
}
else
{
m.insert(pair<string,int>(stu[i].name,stu[i].grade));
if((m[stu[i].name]>=max)&&(nm.count(stu[i].name)))
{
ans=stu[i].name;
break;
}
}
}
cout<<ans<<endl;
}

CodeForces 2A Winner的更多相关文章

  1. codeforces 2A Winner (好好学习英语)

    Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...

  2. CodeForces 2A - Winner(模拟)

    题目链接:http://codeforces.com/problemset/problem/2/A A. Winner time limit per test 1 second memory limi ...

  3. Codeforces 2A :winner

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

  4. CodeForce 2A Winner

    很多人玩一个游戏,每一轮有一个人得分或者扣分,最后分数最高的人夺冠:如果最后有多个人分数都是最高的,则这些人里面,在比赛过程中首先达到或者超过这个分数的人夺冠.现在给定最多1000轮每轮的情况,求最后 ...

  5. Codeforces Beta Round #2 A. Winner 水题

    A. Winner 题目连接: http://www.codeforces.com/contest/2/problem/A Description The winner of the card gam ...

  6. Codeforces Beta Round #2 A. Winner

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

  7. codeforces Winner

    /* * Winner.cpp * * Created on: 2013-10-13 * Author: wangzhu */ /** * 先找出所有选手的分数和中最大的分数和,之后在所有选手的分数和 ...

  8. Codeforces Gym100952 A.Who is the winner? (2015 HIAST Collegiate Programming Contest)

      A. Who is the winner?   time limit per test 1 second memory limit per test 64 megabytes input stan ...

  9. Codeforces Round #603 (Div. 2) C. Everyone is a Winner! 二分

    C. Everyone is a Winner! On the well-known testing system MathForces, a draw of n rating units is ar ...

随机推荐

  1. Node.js:创建应用+回调函数(阻塞/非阻塞)+事件循环

    一.创建应用 如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi.从这个角度看,整个"接收 HTTP ...

  2. Sqlserver 使用CTE如何按子查询排序?

    需求:查出最近有更改的客户信息(按最后更改时间排序,来自SystemLog表LogDateTime字段) 说明: Customer:客户信息表SystemLog:系统日志表,记录所有表信息的增,删,改 ...

  3. docker下搭建gitlab

    [root@localhost ~]# docker run \ > --name='gitlab' \ > -itd \ > --link gitlab_mysql:mysql \ ...

  4. jQuery几个经典表单应用整理回想

    1.文本框获得(失去)焦点 当文本框获得输入焦点时,将该文本框高亮显示,算不得一个应用.仅仅是一个小技巧,能够提高用户体验. [html] view plaincopy <span style= ...

  5. sed 命令编辑文本

    1.sed 概述 sed 是一个非交互式文本编辑器.它能够对文本文件和标准输入进行编辑,标准输入能够是来自键盘输入.文件重定向.字符串.变量.甚至来自于管道文本. 2.sed工作流程简述 sed在处理 ...

  6. .NET反编译之manager,base.AutoScaleMode修复

    使用反编译软件导出项目时,出现警告:设计器无法处理第X 行的代码:this.AutoScaleMode = AutoScaleMode.Font;方法"InitializeComponent ...

  7. 算法笔记_032:最长回文串(Java)

    目录 1 问题描述 2 解决方案 2.1 中心扩展法 2.2 Manacher算法   1 问题描述 给定一个字符串,求它的最长回文子串的长度. 2 解决方案 2.1 中心扩展法 此处,首先枚举出回文 ...

  8. Python enumerate索引迭代

    索引迭代Python中,迭代永远是取出元素本身,而非元素的索引.对于有序集合,元素确实是有索引的.有的时候,我们确实想在 for 循环中拿到索引,怎么办?方法是使用 enumerate() 函数:&g ...

  9. UVA1614(贪心)

    Hell on the Markets Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & %llu [Subm ...

  10. eclipse maven Cannot change version of project facet Dynamic web module to 3.0

      eclipse maven Cannot change version of project facet Dynamic web module to 3.0 (eclipse 修改maven项目的 ...