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. IP addr命令

    我们都知道Windows上查看IP地址是ipconfig, Linux上是ifconfig,但是Linux上还有一个命令叫ip addr可以查看IP地址. 如上图所示命令显示了机器上的所有网卡,大部分 ...

  2. JSP学习笔记(三):Session和Cookie

    一.JSP Session HTTP是无状态协议,这意味着每次客户端检索网页时,都要单独打开一个服务器连接,因此服务器不会记录下先前客户端请求的任何信息.有三种方法来维持客户端与服务器的会话: 1.C ...

  3. java笔试题(5)

    1.Comparable和Comparator接口是干什么的?列出它们的区别. Java提供了只包含一个compareTo()方法的Comparable接口.这个方法可以个给两个对象排序.具体来说,它 ...

  4. WeifenLuo.WinFormsUI.Docking添加关闭功能

    /****************************************************************** * 创建人:HTL * 创建时间:2014-7-8 15:37: ...

  5. ReportStudio中创建日期提示默认值模板

    很多人已经知道可以通过JS给RS中的日期提示控件设置运行前的默认值---------例如: 日期时间段默认为上一个月的开始日和结束日 在系统所有的报表中都这样操作,我们如何快速的引入?和方便下次修改统 ...

  6. 分治算法——Karastsuba算法

    分治(Divide and Conquer)算法:问题能够分解为子问题,每一个问题是能够独立的解决的,从子问题的解能够构建原问题. Divide:中间分.随机分.奇偶分等,将问题分解成独立的子问题 C ...

  7. 【pyhon】黑客用字典暴力破解Zip文件密码原理性展示

    基本原理:用程序把字典文件里拟定好的密码一个个提取出来,去测试zip能否打开 字典文件pass.txt内容: 1224 2121 asdf abcd1234 dwsdsd dssds 程序代码: # ...

  8. jQuery框架开发一个最简单的幻灯效果

    在线演示 在这个课程中,我们将介绍如何使用jQuery来开发一个最简单的图片幻灯效果. 立刻观看互动课程:jQuery框架开发一个最简单的幻灯效果 阅读原文:jQuery框架开发一个最简单的幻灯效果

  9. 关于UbuntuMate的两个问题点:SSH问题处理与自启动项配置

    一.SSH连接报错问题 ssh到某台机器时候,存在如下报错: /usr/bin/xauth: timeout in locking authority file /home/sam/.Xauthori ...

  10. es5 - array - join

    /** * join描述:将数组(或类数组对象)的所有元素连接到一个字符串中并返回此字符串. * join语法:arr .join([ separator]) * join参数:指定用于分隔数组的每对 ...