题目意思就是给出一个各轮选手得分,最后输出分最高的那个人.
如果有多人分数一样高,那就输出先达到这个分数的人.
简单模拟,用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;
}