codeforces--NEFU要崛起——第1场 " B - Winne

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并重点阐述了AI音视频处理的应用场景和实现方法,如语义识别、物体检测、语音变声等。通过实例分析,揭示了技术融合带来的创新解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                                                                                        B -Winner
                                         Time Limit:1000MSMemory Limit:65536KB 64bit IO Format:%I64d & %I64u
 

Description

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", wherename 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 tom) at the end of the game, than wins the oneof 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 follown lines, containing the information about the rounds in "name score" format in chronological order, wherename is a string of lower-case Latin letters with the length from 1 to 32, andscore is an integer number between -1000 and 1000, inclusive.

Output

Print the name of the winner.

Sample Input

Input
3
mike 3
andrew 5
mike 2
Output
andrew
Input
3
andrew 3
andrew 2
mike 5
Output
andrew

 

 

 

 

 

 

 

 

 

 

 

 

 

题意:输入名字和他们所持有的点数 先达到最大者为获胜者 最后输出获胜者的名字

解题:原来做过一道关于dfs的题 里面的将字符串变为数组下标印象深刻 所以开始的时候也是将其转换为数组下标 但是没有考虑到如果输入的是负数这种情况

 所以后面坐了好多改动才过~ 其实我开始也不知道怎么过的~ 开始wa然后就过了 然后又wa了 然后又过了 wokao~

下面的代码稳过:

代码:

 

 

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char name[1000][1000];
char str[1000];
int xiabiao[1000];
int shuzhi[1000];
int m;
int q[10000];
int num;
int k;
int match(char *str)       //就是这一步一直没有过~ 爷爷的~ 
{
	for(int i=0;i<m;++i)
		if(!strcmp(str,name[i]))return i;
	q[m]=0;
	strcpy(name[m],str);
	return m++;
}
int main()
{
	int cas;
	while(cin>>cas)
	{
		m=0;
		int sub;
		for(int i=0;i<cas;i++) 
		{
			cin>>str>>num;
			sub=match(str);
			
			q[sub]+=num;
			xiabiao[k]=sub;//将下标和数值分别放在一个数组里
			shuzhi[k]=q[sub];  
			k++;
		}
	
			int temp=0;                         //找到最大的值 
			for(int i=0;i<m;i++)
		{
			if(temp<q[i])
			temp=q[i];
		}	
		
			int d=0;
				for(int i=k;i>0;i--)      //倒着查找 最后输出最大的下标 
		{
			if(shuzhi[i]>=temp&&q[xiabiao[i]]==temp)
			
			d=xiabiao[i];
			
		}
		cout<<name[d]<<endl;
	}
	return 0;
}


 最后贴出刚开始的时候只考虑是正输入的代码,虽然错了 我觉得当时出来的时候还是挺有感觉的 对以后算做警示吧~

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string.h> 
using namespace std;
int cn;

char name[1000][1000];
int q[10000];
int match(char c[])
{
    int i;
    for ( i=1;i<=cn;i++)
        if (strcmp(name[i],c)==0)
            return i;
    strcpy(name[i-1],c);
    cn++;
    return i-1;
}

int main()
{
	int cas;
	

	int num;
	int a;
	while(cin>>cas)
	{
		num=0;
		memset(q,0,sizeof(q));
		int temp=-1;
		int k=1;
		for(int i=1;i<=cas;i++)
		{
			cin>>name[i]>>num;
			a=match(name[i]);
			
			q[a]=num+q[a];
			
			if(q[a]>temp)
			{
		        temp=q[a];
				k=a;
			}
			
					
		}
		
		cout<<name[k]<<endl;
		
	}
}


 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值