Codeforces 2A Winner
来源:互联网 发布:mysql 登录失败锁定 编辑:程序博客网 时间:2024/05/29 14:43
English
Desc
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.
Examples
input
3mike 3andrew 5mike 2
output
andrew
中文
简介
有一个非常受欢迎的比赛,有如下规则。如果比赛结束后只有他一个人的积分最高,则他是胜利者。每轮都会给出一个人的名字和他的获得的积分(有正有负),如果有二个或二个以上的人积分都是最高的,那么取谁先到达最高分的选手为胜利者。
输入格式
第一行给出一个n(1<=n<=1000),接下来n行
name score
分别代表名字和分数
输出格式
输入胜利者的名字
测试用例
测试输入
3andrew 3andrew 2mike 5
测试输出
andrew
代码
#include<iostream>#include<string>#include<map> using namespace std;map<string, int> m;map<string, int> m2;string name[1001];int num[1001];int main(){ int n; cin >> n; int max = -0x7f7f; string maxName; for (int i = 0; i < n; i++) { cin >> name[i] >> num[i]; m[name[i]] += num[i]; } map<string, int>::iterator it; for (it = m.begin(); it != m.end(); it++) { if (it->second > max) { max = it->second; } } for (int i = 0; i < n; i++) { if (m[name[i]] == max) { m2[name[i]] += num[i]; if (m2[name[i]] >= max) { cout << name[i] << endl; break; } } } return 0;}
- codeforces 2A Winner
- CODEFORCES 2A-Winner
- codeforces 2A. Winner
- Codeforces 2A Winner
- codeforces 2A Winner
- codeforces 2-A Winner
- codeforces 2A.Winner
- Codeforces 2A. Winner
- Codeforces 2A :winner
- CodeForces 2A-Winner
- 【codeforces#2A】Winner
- CodeForces#2A Winner
- CodeForces 2A. Winner
- Codeforces #2 A Winner
- Codeforces 2 A. Winner
- [codeforces] 2A - Winner
- CodeForces - 2A - Winner
- Codeforces 2A Winner
- 深度学习视频教程:深度学习进阶《算法与应用》
- HDU 2255 奔小康赚大钱 (KM算法+二分图最大权匹配)
- java-多态性
- Android 将Activity转化为DialogActivity
- 第1章信号完整性分析概论----新设计方法和仿真测量
- Codeforces 2A Winner
- 转载:如何理解jsp页面中的“<base href="<%=basePath%>">”?
- configure: error: Neither flex nor lex was found.
- 新路程------无法从ubuntu虚拟机copy文件
- 27. Remove Element
- Hive--DML
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
- 脚本实现文本文件在Linux、mac与window下的正常显示
- 基于ACRGIS二次开发实现地物中心坐标点批量提取