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. 如何设置ESXi中的虚拟机随主机一同启动?

    笔者新装了几台ESXi的主机, 其中一台上面运行着一台安装了vCenter的虚拟机.  笔者一路默认, 也没改什么设置. 在试图解决其他问题的过程中, 笔者重启了ESXi. 后来发现vCente登不进 ...

  2. 【干货合集】Docker快速入门与进阶

    收录待用,修改转载已取得腾讯云授权 Docker 在众多技术中,绝对是当红炸子鸡.这年头,如果你不懂一点容器,不学一些Docker,还怎么出去跟人炫耀技术? Docker 也是云计算技术中较为热门的一 ...

  3. 论#include

    1.#include " "与#include <> #include " "表示预编译命令源程序在当前项目下寻找头文件,如果找不到,再到标准头文件 ...

  4. Leet Code OJ 219. Contains Duplicate II [Difficulty: Easy]

    题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ...

  5. java反射--动态加载

    Class.forName("类的全称") 1)不仅表示类的类类型,还表示了动态加载类 2)请区分编译,运行 3)编译时刻加载类是静态加载类,运行时刻加载类是动态加载类 比如下面: ...

  6. 43、Java动态代理一——动态类Proxy的使用

    1.什么是动态代理? 答:动态代理可以提供对另一个对象的访问,同时隐藏实际对象的具体事实.代理一般会实现它所表示的实际对象的接口.代理可以访问实际对象,但是延迟实现实际对象的部分功能,实际对象实现系统 ...

  7. 40、JDBC相关概念介绍

    1.1.数据库驱动 这里的驱动的概念和平时听到的那种驱动的概念是一样的,比如平时购买的声卡,网卡直接插到计算机上面是不能用的,必须要安装相应的驱动程序之后才能够使用声卡和网卡,同样道理,我们安装好数据 ...

  8. 逻辑回归的相关问题及java实现

    本讲主要说下逻辑回归的相关问题和详细的实现方法 1. 什么是逻辑回归 逻辑回归是线性回归的一种,那么什么是回归,什么是线性回归 回归指的是公式已知,对公式中的未知參数进行预计,注意公式必须是已知的,否 ...

  9. Docker配置本地镜像与容器的存储位置

    默认情况下Docker的存放位置为:/var/lib/docker 可以通过下面命令查看具体位置: sudo docker info | grep "Docker Root Dir" ...

  10. ubuntu12.04(64位)下安装Adobe Flash Player

    2012-06-14 10:10:37   第一步,去adobe官方网站就可以,使用方便,打开网站:http://get.adobe.com/cn/flashplayer/根据自己的版本下载需要的.本 ...