PAT-乙-1047 1047 编程团体赛 (20 分)

在这里插入图片描述
在这里插入图片描述

代码

#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的简单使用。

结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zhanggirlzhangboy/article/details/82951815
今日推荐