前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cf------(round 2)A. Winner

cf------(round 2)A. Winner

作者头像
Gxjun
发布2018-03-22 14:17:36
7340
发布2018-03-22 14:17:36
举报
文章被收录于专栏:mlml

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

代码语言:javascript
复制
3
mike 3
andrew 5
mike 2

Output

代码语言:javascript
复制
andrew

Input

代码语言:javascript
复制
3
andrew 3
andrew 2
mike 5

Output

代码语言:javascript
复制
andrew

此题不大好懂,就是要你求出最大分数而且最先得到这个最高分的那个人的名字

思路: 第一步: 我们先求出所有人的最终得分
      第二步: 我们求出最终得分的最高分:
      第三部: 我们求出第一个得到最高分,而且最终得分也是最高分的那个人,那必定是最先出现的那个人.....

代码:
代码语言:javascript
复制
 1 #include<iostream>
 2 #include<map>
 3 using namespace std;
 4 struct node
 5 {
 6     int score;
 7     string name;
 8 }ss[1005];
 9 int main(){
10 
11  string winner;
12  int n,maxsc;
13  map<string ,int>str;
14  //freopen("test.in","r",stdin);
15  while(cin>>n){
16      if(!str.empty()) str.clear();
17     for(int i=0;i<n;i++){       //求出最终态势
18       cin>>ss[i].name>>ss[i].score;
19       str[ss[i].name]+=ss[i].score;
20     }
21     //求出最大的值
22     maxsc=str[ss[0].name];
23     for(int i=1;i<n;i++){
24      if(maxsc<str[ss[i].name]){
25        maxsc=str[ss[i].name];
26       }
27     }
28     map<string ,int>check;      //这个表示过程态势
29     for(int i=0;i<n;i++){
30      check[ss[i].name]+=ss[i].score;
31      if(check[ss[i].name]>=maxsc&&str[ss[i].name]>=maxsc){
32          winner=ss[i].name;
33          break;
34      }
35     }
36   cout<<winner<<endl;
37 }
38  return 0;
39 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-08-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档