zoukankan      html  css  js  c++  java
  • CodeForce 2A

    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

    题意:
      给出N轮游戏中的情况,求最后谁胜利了

      模拟水题,模拟----细节最重要
    AC代码:
    # include <iostream>
    # include <cstdio>
    # include <cstring>
    # include <algorithm>
    # include <map>
    using namespace std;
    
    const int MAXN = 1010;
    const int N =  50;
    
    int n , pos;
    int vis[MAXN];
    int p[MAXN];
    char start[MAXN][N];
    char name[MAXN][N];
    map<string , int> mp;
    
    int main()
    {
    	int max , cnt;
    	cin >> n;
    
    	for(int i = 0 ; i < n ; i++)
    		scanf("%s %d" , start[i] , &p[i]);
    
    	
    	max = 0 , pos = 0;
    	for(int i = 0 ; i < n ; i++)
    	{
    		int flag = -1;
    
    		for(int j = 0 ; j < pos ; j++)
    		{
    			if(!strcmp(name[j] , start[i]))
    			{
    				flag = j;
    				break;
    			}
    		}
    		if(flag == -1)
    			strcpy(name[pos++] , start[i]);
    	
    		mp[start[i]] += p[i];
    	} 
    
    	memset(vis , 0 , sizeof(vis));
    	for(int i = 0 ; i < pos ; i++)
    		max = max < mp[name[i]] ? mp[name[i]] : max;
    	for(int i = 0 ; i < pos ; i++)
    	{
    		if(max == mp[name[i]])
    		vis[i] = 1;
    	}
    
    	mp.clear();
    	for(int i = 0 ; i < n ; i++)
    	{
    		mp[start[i]] += p[i];
    		int tmp = 0;
    		for(int i = 0 ; i < pos ; i++)
    		{
    			if(tmp < mp[name[i]])
    			{
    			tmp = mp[name[i]];
    			cnt = i;
    		}
    	}
    
    		if(tmp >= max && vis[cnt])
    			break;
    	}
    
    	printf("%s
    " , name[cnt]);
       
       return 0;
    }
    
    
    
    生命不息,奋斗不止,这才叫青春,青春就是拥有热情相信未来。
  • 相关阅读:
    c# Action,Func,Predicate委托
    c# 匿名方法
    IIS网站无法启动,提示 另一个程序正在使用此文件
    c# Http下载
    mciSendString详解(转)
    【NOIP2006PJ】数列(sequence)题解
    2020.04.29【NOIP普及组】模拟赛C组30总结
    【USACO 2019 December Silver】Milk Visits题解
    【USACO 2019 February Bronze】Measuring Traffic 题解
    【USACO 2019 February Bronze】Measuring Traffic 题解
  • 原文地址:https://www.cnblogs.com/lyf-acm/p/5787750.html
Copyright © 2011-2022 走看看