PAT-BASIC1032——挖掘機技術哪家強
阿新 • • 發佈:2018-12-17
題目描述:
知識點:計數
思路:用一個大小為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++解題報告: