题目链接:http://codeforces.com/problemset/problem/2/A

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 <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<string, int> a,b;
string s[1017]; int main()
{
int x[1017];
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> s[i] >> x[i];
a[s[i]]+=x[i];
}
int maxx = 0;
for(int i = 1; i <= n; i++)
{
if(a[s[i]] > maxx)
maxx = a[s[i]];
} for(int i = 1; i <= n; i++)
{
b[s[i]]+=x[i];
if((b[s[i]]>=maxx) && (a[s[i]]>=maxx))//在终于分数是最大的人中,选首先达到最大分数的人
{
cout << s[i];
break;
}
}
return 0;
}

CodeForces 2A - Winner(模拟)的更多相关文章

  1. CodeForces 2A Winner

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

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

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

  3. Codeforces 2A :winner

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

  4. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  5. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  6. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  7. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  8. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  9. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

随机推荐

  1. 【BZOJ】3697: 采药人的路径

    3697: 采药人的路径 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1718  Solved: 602[Submit][Status][Discu ...

  2. bzoj 2809: [Apio2012]dispatching -- 可并堆

    2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MB Description 在一个忍者的帮派里,一些忍者们被选中派 ...

  3. python开发_textwrap文本样式

    在看python的API的时候,发现python的textwrap在处理字符串样式的时候功能强大 在这里我做了一个demo: textwrap提供了一些方法: wrap(text, width = 7 ...

  4. ExtJS ComboBox同时加载远程和本地数据

    ExtJS ComboBox同时加载远程和本地数据 原文:http://gblog.hbcf.net/index.php/archives/233 ComboBox比较特殊需求,将远程数据和本地数据同 ...

  5. Druid 常见问题

    https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

  6. Java之基于Eclipse搭建SSH框架(上)

    http://blog.csdn.net/snowwitch/article/details/50925382 http://www.cnblogs.com/hww123/archive/2016/0 ...

  7. C# http Get/POST请求封装类

    C#HttpHelper官方产品发布与源码下载---苏飞版 http://www.sufeinet.com/thread-3-1-1.html 在C#用HttpWebRequest中发送GET/HTT ...

  8. 一段js的思考

    写了很久JS,还以为这段代码可以正常输出,谁知道输出超乎我的形象: <!DOCTYPE html> <html> <head> <meta charset=& ...

  9. mmap函数使用

    UNIX网络编程第二卷进程间通信对mmap函数进行了说明.该函数主要用途有三个:1.将一个普通文件映射到内存中,通常在需要对文件进行频繁读写时使用,这样用内存读写取代I/O读写,以获得较高的性能:2. ...

  10. OpenERP实施记录(11):入库处理

    本文是<OpenERP实施记录>系列文章的一部分. 在前面的文章中,业务部门接到沃尔玛3台联想Y400N笔记本电脑的订单,采购部门完成了补货处理.因为该产品的“最少库存规则”里面定义了“最 ...