PAT (Basic Level) 1032 挖掘机技术哪家强

题意

给出N个人的学校和成绩,求成绩和最高的学校,并输出。

思路

水~

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		mp[x] += y;
	}
	int id, sum = -1;
	for (auto e : mp) {
		if (e.second > sum) {
			sum = e.second;
			id = e.first;
		}
	}
	cout << id << ' ' << sum << '\n';
	return 0;
} 

HINT

不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !

发布了32 篇原创文章 · 获赞 15 · 访问量 1016

猜你喜欢

转载自blog.csdn.net/abcdefbrhdb/article/details/104572326