梧桐听雨丶 2019-04-20 20:49
浏览 486

ACM CodeForces 2A - Winner 求大神指导

题目意思就是给出一个各轮选手得分,最后输出分最高的那个人.
如果有多人分数一样高,那就输出先达到这个分数的人.
思路大概是,把数据都录进去然后按分数排序,如果分数相同按最后一次出现该名词时的下标排序
样例可以过,感觉思路是对的,但是总是第六次测验wa,请大佬指正;

#include
#include
#include
#include
#include
using namespace std;
struct node{
int score = 0;
int index;
};

bool cmp(const pair& a, const pair& b)
{
if((a.second).score != (b.second).score)
return (a.second).score > (b.second).score;
else
return (a.second).index < (b.second).index;
}//按规则排序
int main()
{
ios::sync_with_stdio(false);
int T; //测试用例个数
cin >> T;
mapnums;
for(int i = 0;i < T;i++)//数据录入
{
string a;
int b;
cin >> a >> b;
nums[a].score += b;//记分
nums[a].index = i;//有相同分数时用于比较得到该分数的顺序先后。
}
vector< pair > x(nums.begin(),nums.end());//把map放到容器中排序
sort(x.begin(),x.end(),cmp);
cout << x[0].first <<endl;
return 0;
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥50 汇编语言除法溢出问题
    • ¥65 C++实现删除N个数据列表共有的元素
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波