【思路】:模拟。不需要结构体,用数组记录就可以。注意,题目中说了学校“从1开始连续编号”。
【AC代码】:
#include <iostream> #include <cstdio> using namespace std; const int maxn = 100000+10; int school[maxn]; int main() { //freopen("in.txt", "r", stdin); int n = 0, i = 0; cin >> n; for (i = 0; i < n; i++) { int schId = 0, score = 0; cin >> schId >> score; school[schId] += score; } int id = 0, max_sco = -1; for (i = 1; i <= n; i++) { if (school[i] > max_sco) { max_sco = school[i]; id = i; } } cout << id << " " << max_sco; }
原文地址:http://blog.csdn.net/weijj6608/article/details/44860569