CodeForce 2A —— Winner

A. Winner

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

3
mike 3
andrew 5
mike 2

output

andrew

input

3
andrew 3
andrew 2
mike 5

output

andrew


思路:

该题求解玩家的最高分获得者,需要说明的一点是:如果有最高分相同的玩家,即最终得分都是最高分,那么其中最先达到或超过最高分(score >= max, 原题说明who scored at least m points first)的玩家获胜。

该题由于可能要求得最先达到最高分的玩家,因此使用两次计算的方法,第一次先求得所有玩家的最终得分,并从中选取最高分;第二次为了找到最先达到最高分的玩家,需要再计算一遍得分过程,当score>=max时,便是最终答案。

坑点:由于会有扣分情况,即出现负数,所以不能直接一次循环比较当前max值得到最高分,因为在扣分后,max可能不再满足是当前选手中的成绩(例如,max是100,刚好该选手现在被扣分,成了90,但是max的值并未被更新为当前所有成绩的最大值)


code:

#include <iostream>
#include <string>
#include <map>
using namespace std;int main() {map< string, int > _map;  //记录所有玩家最终成绩map< string, int > _map2;  //二次计算得最先达到最高分的玩家string name[1000];int score[1000], n, max = -99999999;cin >> n;for( int i = 0; i < n; i++ ) {cin >> name[i] >> score[i];_map[ name[i] ] += score[i];}/* 获得最高分 */map< string, int >::iterator it;for( it = _map.begin(); it != _map.end(); it++ ) {if ( max < it->second ) {max = it->second;}}for( int i = 0; i < n; i++ ) {if ( _map[ name[i] ] == max ) {_map2[ name[i] ] += score[i];/* 最先达到最高分 */if ( _map2[ name[i] ] >= max ) {  cout << name[i];break;}}}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/381939.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

GARFIELD@12-30-2004

tele-murderer 转载于:https://www.cnblogs.com/rexhost/archive/2004/12/30/84230.html

[codevs] 1098 均分纸牌

均分纸牌 题目描述 Description 有 N 堆纸牌&#xff0c;编号分别为 1&#xff0c;2&#xff0c;…, N。每堆上有若干张&#xff0c;但纸牌总数必为 N 的倍数。可以在任一堆上取若于张纸牌&#xff0c;然后移动。   移牌规则为&#xff1a;在编号为 1 堆上取的纸牌&#xf…

uva 11536——Smallest Sub-Array

题意&#xff1a;给定n个数&#xff0c;这n个数在m的范围之内。v[i](v[i-1]v[i-2]v[i-3])%m1; 然后求一个最短连续子序列使得序列内包括1-k个数。 思路&#xff1a;枚举。枚举以v[i]结尾的最短序列。用ct维护已经找到的k个数中的个数&#xff0c;queue跳转区间。 code&#x…

好消息,关于2005的default provider

好消息&#xff0c;关于2005的default provider 看到一则消息&#xff0c;说在vs.net 2005 bETA 2以后&#xff0c;关于Membership, Roles, Profile and Personalization 的会默认使用 SQL SERVER 2005的provider(现在BETA 1使用的是ACCESS&#xff0c;所以在做MEMBERSHIP&…

[Qt] 解决toggled无法触发setVisible

解决toggled无法触发setVisible 解决方法&#xff1a; 在QT Designer中&#xff0c;创建QPushButton时需要将按钮修改为checkable。在默认情况下&#xff0c;checkable是不选中的&#xff0c;默认为触发按钮&#xff08;trigger button&#xff09;&#xff0c;也就是按下之后…

周华健,歌声伴我成长(四)

1997年&#xff0c;经典的朋友《朋友》 朋友 这些年一个人 风也过雨也走 有过泪有过错 还记得坚持甚麽 真爱过才会懂 会寂寞会回首 终有梦终有你在心中 朋友一生一起走 那些日子不再有 一句话一辈子 一生情一杯酒 朋友不曾孤单过 一声朋友你会懂 还有伤还有痛 还要走还有我 199…

hihoCoder挑战赛16 A—— 王胖浩与三角形

思路&#xff1a;开始没有思路&#xff0c;想到了用三边乱搞&#xff08;每条边按照比例增加&#xff09;然而样例都无法通过。后来想到了海伦公式sqrt((abc)(ab-c)(bc-a)(ac-b))/4&#xff0c;那么这样以来就是让这个三角形趋于正三角形了&#xff0c;即三边的方差最小&#x…

虚析构函数

需要虚析构函数的原因&#xff1a; 首先看一下这段代码&#xff1a; #include <iostream> using namespace std;class A { private: int *a; public: A() { a new int; cout << "A::A() is called.\n"; }~A() { delete a; cout << "A::~A(…

关于编写流程的一些经验

关于编写流程的一些经验 各位同行有时编写较多的流程。在很多情况下需要修改其他同事的流程。在修改的过程中需要了解流程的结构、看懂原流程各部分编写的情况 &#xff0c;了解每个变量存放的内容。但由于在编写过程中会不断的修改增加流程&#xff0c;所以有时有些地方的情况…

CodeForces 501B——Misha and Changing Handles

题意&#xff1a;给定一些姓名的原来姓名和修改后的名字&#xff0c;由于一个名字可以被修改多次&#xff0c;所以求所有用户的初始姓名和当前姓名。 思路&#xff1a;暴力。数据量很小&#xff0c;对于每次修改直接判断其是否有原来的名字即可&#xff0c;有的话更新&#xff…

静态多态 动态多态

一. 静态多态 1. 何为静态多态&#xff1f; 又称编译期多态&#xff0c;即在系统编译期间就可以确定程序将要执行哪个函数。例如&#xff1a;函数重载&#xff0c;通过类成员运算符指定的运算。 2. 示例代码 函数重载示例&#xff1a; class A { public:A() {}A( int x ) …

来几个FUNNY PICS,让大家笑一笑!

点解蜡笔小新成日都可以甘猥琐&#xff5e;转载于:https://www.cnblogs.com/hdclub/archive/2005/04/26/145761.html

uva 10954——Add All

<p>题意&#xff1a;给定一个序列&#xff0c;然后从中选择两个数&#xff0c;相加后放入原来的序列&#xff0c;消耗的费用为两个数 的和&#xff0c;问最小的代价。</p><p></p><p>思路&#xff1a;贪心。用优先队列维护&#xff0c;每次取得时…

jsoncpp学习笔记

jsoncpp 一. json基础 类型&#xff1a; 1. Json::Value为主要数据类型&#xff1b; 2. Json::Reader将文件流或字符串创解析到Json::Value中&#xff0c;主要使用parse函数&#xff1b;3. Json::Writer&#xff1a;与JsonReader相反&#xff0c;将Json::Value转换成字符串流…

Together与Visual.Studio.NET的结合使用(三)

通用选项&#xff1a; 图二十九&#xff1a;通用选项 Delete confirmation&#xff1a;此选项定义当你删除一个元素的时候是否需要进行确认。 Automatically enable Together VS.NET support for opened projects&#xff1a;当打开一个已存在的项目时&#xff0c;是…

uva 1152 ——4 Values whose Sum is 0

题意&#xff1a;给定4个n元素集合&#xff0c;要求从每个集合中选择一个数&#xff0c;使得ABcd0&#xff0c;问存在多少种方法。 思路&#xff1a;枚举hash判断。直接枚举4次方的算法会超&#xff0c;那么只需要枚举ab&#xff0c;然后在cd的和中查找等于-&#xff08;ab&…

c++ STL 全排列

在c的STL中有函数可以直接对数组元素进行全排列&#xff0c;即next_permutation和pre_permutation&#xff0c;这两个函数都可以实现全排列&#xff0c;只是排列的顺序不同&#xff0c;next_permutation作用为向后排序&#xff0c;而pre_permutation作用为向前排序。 需要头文…

创建下标为1-10的整形数组

创建下标为1-10的整形数组 Array intArr Array.CreateInstance(typeof(int), newint[]{10}, newint[]{1}); posted on 2005-05-11 16:32 K3 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/sskset/archive/2005/05/11/153238.html

uva 1605 ——Building for UN

题意&#xff1a;给定n&#xff0c;让设计一个大楼&#xff0c;使得n个国家任意两个国家都相邻或上下层。 思路&#xff1a;由于题目中的限定很小&#xff0c;可以这样考虑&#xff0c;只设计两层&#xff0c;每层的第i行为同一个国家&#xff0c;第二层的所有第j列为同一个国家…

友元函数 友元类 友元成员函数

友元 一般来说&#xff0c;类内的私有数据是对外不可见的&#xff0c;但在有些情况下&#xff0c;我们需要在类外对该类的私有数据进行访问&#xff0c;这就需要用到一种新技术——友元&#xff08;friend&#xff09;&#xff0c;即在声明前添加关键字friend。 友元关系是单向…