有没有C语言做的3A游戏,codeforces-3A-A. Winner (C++ && 简单模拟)

题目意思就是给出一个各轮选手得分,最后输出分最高的那个人.

如果有多人分数一样高,那就输出先达到这个分数的人.

简单模拟,用stl的map来做.

1.统计每人分数,顺便把每轮的情况也记下来.

2.统计出最高分.

3.遍历每个人的总得分,找到分数最高的那些人.

4.遍历每轮的情况,第一个达到最高分的人,输出就好了.

#include

#include

#include

#include

#include

using namespace std;

//一开始没有考虑到负数的情况,出现了错误。出现负数的话,分数就会下降,之前的最大值就不会对。

map round;

map round2;

string name[1005];

int score[1005];

int main()

{

int count,i;

cin>>count;

round.clear();

int max = -1000005;

string max_name;

for(i=1;i<=count;i++)

{

cin>>name[i]>>score[i];

round[name[i]] += score[i];

}

for(i=1;i<=count;i++)

{

if(round[name[i]]>max)

{

max=round[name[i]];

}

}

for(i=1;i<=count;i++)

{

if(round[name[i]] == max)

{

round2[name[i]] += score[i];

if(round2[name[i]]>=max) //最先到达,这里的大于号就是考虑到出现负数的情况,分数越来越小

{

cout<

return 0;

}

}

}

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值