PAT (Basic Level) 1032 挖掘机技术哪家强 (20 point(s))
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> school;
for(int i = 0; i < n; i++) {
int num, score;
cin >> num >> score;
school[num] += score;
}
int max = -1, index;
for(auto s : school)
if(max < s.second){
max = s.second;
index = s.first;
}
cout << index << " " << max;
}
int max = -1, index;
比较最大值需要初始化为 -1 否则如果最大成绩为 0 可能无法正确判断。
浙公网安备 33010602011771号