1. 程式人生 > >PATB1032. 挖掘機技術哪家強(20)

PATB1032. 挖掘機技術哪家強(20)

在第二個迴圈裡,j<10010,而不是j<n

AC程式碼

#include<stdio.h>

int main() {
    int n;
    scanf("%d",&n);
    int number[100010]={0};
    int ID;
    int score;
    for(int i=0;i<n;i++){
      scanf("%d %d",&ID,&score);
      number[ID]+=score;
    }
    int maxIndex,maxScore=-1;
    for(int j=0;j<100010;j++){
        if(number[j]>maxScore)
          {
            maxScore = number[j];
            maxIndex = j;
          }
      }

      printf("%d %d",maxIndex,maxScore);
  return 0;
}