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. 【转载】Redis在新浪微博中的应用

    转载自文章 http://blog.me115.com/2013/12/19/redis-e5-9c-a8-e6-96-b0-e6-b5-aa-e5-be-ae-e5-8d-9a-e4-b8-ad-e ...

  2. vxer

    Virus Maker 或者 Virus eXchanger 的简称,(有时候中文也叫做毒客),是一群追求完美.极致代码的病毒程序员. 1.VXer简介: VXer热爱汇编,熟悉各种处理器架构,致力于 ...

  3. Thinkphp学习笔记-controller与view绑定

    $this->display(); 通过上面的代码则可以输出controller所对应的view

  4. [ACM] POJ 2524 Ubiquitous Religions (并查集)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23093   Accepted:  ...

  5. Oracle日期周具体解释以及周開始结束时间计算

    1 ORACLE中周相关知识描写叙述 1.1           日期格式化函数 TO_CHAR(X [,FORMAT]):将X按FORMAT格式转换成字符串. X是一个日期,FORMAT是一个规定了 ...

  6. matlab练习程序(三阶张量T-QR分解)

    转自:http://www.cnblogs.com/tiandsp/archive/2012/10/31/2747971.html 这里所谓的张量和黎曼那里的张量是不一样的,那个张量更多的用在物理上, ...

  7. setup factory 打包VB 工程

    setup factory 使用起来很简单你可以如下:1.你把你刚编译出来的exe和相关的资源文件复制到某一空目录下.把exe文件添加到setup factory里之后,在列表里右键,属性里面可以设置 ...

  8. oracle 三表关联查询

      oracle 三表关联查询 CreationTime--2018年7月4日17点52分 Author:Marydon 左连接实现三表关联 表A--------------------------- ...

  9. 模拟登陆百度 python

    from time import sleep from selenium import webdriver driver = webdriver.Firefox() driver.get('http: ...

  10. servlet awt随机图片验证码

    package rd.test; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java. ...