Codeforces Beta Round #2

Source: Internet
Author: User
Tags rounds

Codeforces Beta Round #2

 

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 participant 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 equalsM) At the end of the game, than wins the one of them who scored at leastMPoints 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 numberN(1 hour ≤ hourN  ≤    1000 ),NIs the number of rounds played. Then followNLines, 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
3mike 3andrew 5mike 2
Output
andrew
Input
3andrew 3andrew 2mike 5
Output
andrew

 

Question: Give a score for each round, and finally output the person with the highest score.

If there are multiple people with the same score, the output will first reach the score.

Problem: It is simulated. Use stl map directly.

First, traverse each person's score to calculate the highest score. Then, traverse the first person to reach the highest score among these people.

Write map for the first time .. It may not be very useful.

 

#include 
 
  #include 
  
   #include
   using namespace std;const int maxn = 1011;char str[maxn][36];int score[maxn];int main(){    int n;    scanf(%d, &n);    map
    
      name, nametmp;    int nans = 0;    for(int i = 0; i < n; ++i){        scanf(%s%d, str[i], &score[i]);        name[str[i]] += score[i];    }    for(int i = 0; i < n; ++i){        if(name[str[i]] > nans){            nans = name[str[i]];        }    }    for(int i = 0; i < n; ++i){        if(name[str[i]] == nans){            nametmp[str[i]] += score[i];            if(nametmp[str[i]] >= nans){                puts(str[i]);                break;            }        }    }    return 0;}
    
  
 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.