

代码
#include <iostream>
#include <map>
using namespace std;
int main() {
int n;
scanf("%d", &n);
map<int, int> m;
int championNum = 0;
int championScore = 0;
for(int i=0; i<n; i++) {
int team, member, score;
scanf("%d-%d %d", &team, &member, &score);
if(m[team]) {
m[team] += score;
} else {
m[team] = score;
}
if(m[team]>championScore) {
championNum = team;
championScore = m[team];
}
}
printf("%d %d\n", championNum, championScore);
return 0;
}
注解
map的简单使用。
结果

本文介绍了一个使用C++和标准模板库(map)实现的竞赛评分系统。通过读取参赛队伍的得分,系统能够实时更新并显示当前领先的队伍及其总分。此代码示例展示了如何利用map数据结构来高效地管理和更新多个队伍的得分。
3157

被折叠的 条评论
为什么被折叠?



