PAT-BASIC1032——挖掘机技术哪家强
我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC
原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805289432236032
题目描述:
知识点:计数
思路:用一个大小为100001的数组来保存每一个队伍的分数
时间复杂度是O(n),其中n为输入的参赛人数。空间复杂度是O(100001)。
C++代码:
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int queue[100001];
for(int i = 0; i < 100001; i++){
queue[i] = 0;
}
int tempQueue;
int tempScore;
for(int i = 0; i < n; i++){
cin >> tempQueue >> tempScore;
queue[tempQueue] += tempScore;
}
int maxIndex = 0;
for(int i = 0; i < 100001; i++){
if(queue[i] > queue[maxIndex]){
maxIndex = i;
}
}
cout << maxIndex << " " << queue[maxIndex] << endl;
return 0;
}
C++解题报告: