题干:

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

题目大意:

给出一些名字和分数,正的表示加分,负的表示减分,要求你求出最大分数而且最先得到这个最高分的那个人的名字

解题报告:

这题坑还是很多的。。你不能在线维护一个最大值,因为这个最大值还可能减下来,,你需要看的是最后比赛完了以后的最大值,记录那个最大值。并且最后判断输出的时候也不能直接找到第一个大于maxx的就停止搜索了,因为这个人也可能后来有负分导致最终分数小于maxx。

AC代码:

#include<bits/stdc++.h>using namespace std;
const int INF = 0x3f3f3f3f;
map<string, int> mp;
int main()
{int n,sc[1000 + 5];//sc代表分数 char s[1000 + 5][50];int maxx = -INF;cin>>n;for(int i = 1; i<=n; i++) {scanf("%s %d",s[i],&sc[i]);mp[s[i]]+=sc[i];
//      maxx =max(maxx,mp[s[i]]); }for(int i = 1; i<=n; i++) {maxx = max(maxx,mp[s[i]]);}map<string,int > mpp;for(int i = 1; i<=n; i++) {mpp[s[i]] +=sc[i];if(mpp[s[i]] >= maxx &&mp[s[i]] == maxx ) {printf("%s\n",s[i]);break; } }return 0 ;} 

【CF#2A】Winner(模拟 STL-map)☆相关推荐

  1. C++ 笔记(24)— STL map 类(map实例化、插入、查找、删除)

    1. STL 映射类简介 map 和 multimap 是键-值对容器,支持根据键进行查找,区别在于,后者能够存储重复的键,而前者只能存储唯一的键. 为了实现快速查找, STL map 和 multi ...

  2. STL map 简介

    STL map 简介 转载于:http://www.cnblogs.com/TianFang/archive/2006/12/30/607859.html 1.目录 map简介 map的功能 使用ma ...

  3. 结构体作为STL map的key时需要注意什么? (某公司招聘面试试题)已跪~~~~(_)~~~~

    某公司招聘的面试环节, 有这样一个题目:结构体作为STL map的key时需要注意什么? 对于懂STL map的同学来说, 这个题目还是比较easy的, 先看程序: #include <iost ...

  4. 模拟STL链表类的实现

    模拟STL链表类的实现 STL内部定义了多种容器和迭代器,方便了数据结构类的使用,且不需关注内部源码.为了方便个人使用习惯,我又重写了一个链表类,作为学C++后的第一个项目作业.我将其命名为clist ...

  5. Dictionary,hashtable, stl:map有什么异同?

    Dictionary,hashtable, stl:map有什么异同? 相同点:字典和map都是泛型,而hashtable不是泛型. 不同点:三者算法都不相同 Hashtable,看名字能想到,它是采 ...

  6. C++ STL map的使用

    C++ STL map的使用   2009-12-11 作者:tanker1024 来源:tanker1024的blog   1.map简介 map是一类关联式容器.它的特点是增加和删除节点对迭代器的 ...

  7. 学习STL map, STL set之数据结构基础

    STL map和set的使用虽不复杂,但也有一些不易理解的地方,如: 或许有得人能回答出来大概原因,但要彻底明白,还需要了解STL的底层数据结构. C++ STL 之所以得到广泛的赞誉,也被很多人使用 ...

  8. STL map与Boost unordered_map - 有何不可的日志 - 网易博客

    STL map与Boost unordered_map - 有何不可的日志 - 网易博客 STL map与Boost unordered_map 2012-03-30 16:06:26|  分类: c ...

  9. STL map 内存改变,迭代器失效,_Isnil(_Ptr)和红黑树

    STL map 内存改变,迭代器失效,_Isnil(_Ptr)和红黑树 最近在做项目时发现一个crash的问题,当时得到的dmp文件显示crash在一个以map为循环变量的循环中,crash位置在如下 ...

  10. stl::map之const函数访问

    如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...

最新文章

  1. Kafka学习-复制
  2. linux经常使用解压缩命令
  3. mysql 空闲几分钟速度变慢,MYSQL 运作一小段时间后,速度变得奇慢。而CPU基本空闲状态...
  4. 2021年3月15日_读书|总结笔记目录
  5. 云小课|想实现资源全自动备份?看完这篇秘籍,不再蕉绿~
  6. java 正则 惰性匹配_正则表达式 - 贪婪与非贪婪(惰性)
  7. RabbitMQ交换器Exchange
  8. 成功EDM电子邮件营销的要素和目标分析
  9. 使用C#如何写入/读取注册表信息
  10. 软件项目管理案例教程韩万江课后习题答案第四版
  11. 淘宝商城事件:中小卖家缺失的互联网信任
  12. 利用SSR修正的RTKLIB PPP测试
  13. (附源码)spring boot中小学餐饮配送系统 毕业设计645661
  14. TriSun PDF to X中文版批量pdf转换功能
  15. Beetl开源那些事3
  16. STM32学习之ILI9341控制显示屏输出(一)
  17. hive full join多表多关联键联合查询
  18. 小马哥----高仿三星note3 N9006主板型号A202 高通芯片刷机拆机图示
  19. PHP实现图片上传功能
  20. python 12306查询不到车次_python爬取12306火车车次信息

热门文章

  1. java中sofa并发访问,云上的日子:用块存储、文件存储还是对象存储?
  2. php设置cookie值,PHP如何设置和取得Cookie值
  3. oracle sal01,oracle中 all any in的用法
  4. matlab将数据输出到excel中,matlab将数据保存为excel表格-怎样将MATLAB中的数据输出到excel中...
  5. java 默认排序方式_Java Collections.sort()实现List排序的默认方法和自定义方法
  6. 怎么恢复oracle的包,【学习笔记】使用dbms_backup_restore包恢复数据库
  7. OpenSceneGraph 笔记–如何导出三角形数据
  8. Asterisk入门系列
  9. 坦克大战代码_坦克大战系列文章-坦克大战简介
  10. 黑马程序员顺义校区php_黑马程序员:从PHP零基础到月薪11K为何送锦旗给班主任?...