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

划线部分均为曾经理解错误的地方
这道题目的意思是指,有一群人在玩游戏,每次都可以得到一个分数,这个分数可以是正数,也可以是负数,如果最后过程中 ,有人的累计分数小于零,则意味着出局,
后面得的分数再高也无意义求出分数最大的人的名字,如果最后得到的最大分数有很多人,则按照第一个得到这个分数的人胜利。

这道题目明显是用容器map来写,虽然map可以进行排序,但是map是按照键值来进行排序的,而且,有可能有多个相同的数据,所以,不能够仅仅写一次,可以写三遍for循环进行鉴别,第一层,将每个人所得到的分数进行累加,得到所有人的最后分数,
第二层,逐一判断,确认最大的分数是多少,
第三层,再进行一次新的累加,确认最先达到最大分数的人,输出结果。

代码

#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
string a[10100];
int b[10100];
int main()
{int n;map<string,int> c,d;cin>>n;for(int i=0;i<n;i++){cin>>a[i]>>b[i];c[a[i]]+=b[i];}int maxx=0;for(int i=0;i<n;i++){if(c[a[i]]>maxx)maxx=c[a[i]];}for(int i=0;i<n;i++){d[a[i]]+=b[i];if(d[a[i]]>=maxx&&c[a[i]]==maxx){cout<<a[i]<<endl;break;}}return 0;
}

Winner 赢家 (2A - Winner) map相关推荐

  1. 【Codeforces】 2A - Winner (map)

    http://codeforces.com/problemset/problem/2/A So, if two or more players have the maximum number of p ...

  2. CodeForce 2A —— Winner

    A. Winner The winner of the card game popular in Berland "Berlogging" is determined accord ...

  3. Codeforces Beta Round #2-A. Winner——算法笔记

    题目链接:http://codeforces.com/problemset/problem/2/A 题目描述: The winner of the card game popular in Berla ...

  4. 2A. Winner

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

  5. WINNER II信道模型与WINNER+信道模型概述

    目录 1.WINNER II 2.WINNER+ 目前信道模型主要分为准确信道模型.随机信道模型.统计信道模型.其中随机信道模型集和其他两种模型的优点,成为主流的信道模型.随机模型中基于几何统计的随机 ...

  6. react中使用构建缓存_通过在React中构建Tic Tac Toe来学习ReasonML

    react中使用构建缓存 3. 7. 2018: UPDATED to ReasonReact v0.4.2 3. 7. 2018:更新为ReasonReact v0.4.2 You may have ...

  7. ssis sql_如何在SSIS中使用SQL随机数

    ssis sql 介绍 (Introduction) In this article, we will show how to work with SQL random numbers in SSIS ...

  8. CF 2022寒假练习

    CF 2022寒假练习 CF_2A Winner 链接 CF_2A Winner 题目大意 有一个游戏,由nnn个玩家参与,每一轮会有一个玩家获得sss点数.游戏最后一轮结束后,点数最多的玩家获胜.如 ...

  9. 统计了300课时的代码,得到学Python需要掌握的1024个英语单词

    对话框回复「导航」获取历史推送 与非学堂 专注青少年信息技术教育,探讨少儿编程的教与学,交流技巧.分享资源. 一批孩子学业有成,一批新人又开始成长. ​ 曹老师对之前的同学学过的300课Python代 ...

最新文章

  1. 733.图像渲染(主讲题意)
  2. sort,uniq,fmt,wc,提取开头和结尾的命令的使用
  3. HTML之iframe内联框架
  4. c++ windows获得当前工作目录文件_使用命令行修改当前工作目录
  5. 很遗憾!iPhone 12内部CAD设计图流出:刘海并未缩小
  6. visio交叉线去掉交叉点弯曲方法
  7. Object有哪些公用方法?
  8. fedora core 7下如何安装Fcitx小企鹅输入法
  9. c++多线程——同步并发
  10. HDU 1862 EXCEL次序 (排序水问题)
  11. 如何用C语言实现批量修改文件类型
  12. Windows和ubuntu互传文件
  13. IOC 之深入理解 Spring IoC
  14. MysqlWorkbench中无法显示表[tables could not be fetched]
  15. Systemback使用精简教程
  16. INPUT输入框灰体提示
  17. moocpython程序设计答案_中国大学MOOC免费答案_Python程序设计答案第七章节答案
  18. Ubuntu16.04 装机之后要做的二十件事
  19. 泛微oa数据库之查询流程批次条件、出口条件
  20. 一个类似JQuery的精简版框架

热门文章

  1. 捕鱼达人 Java 休闲小游戏 源码分享
  2. MYSQL实践基础-快速入门学习-纪录
  3. 视唱练耳小课堂——音程 (上)
  4. 无法停止服务 请求的控件对此服务无效
  5. web前端之2048网页版游戏
  6. POI导出excel执行公式 公式不生效问题
  7. Hibernate-Validater自定义组序列分组校验
  8. 通信原理(3)载波传输PSK
  9. 超百人录取985研究生!东南大学计算机学院毕业情况
  10. Rust 和 ScyllaDB NoSQL:提高性能的 3 种方法