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

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

超過 color tro nbsp 組織 學校 ons 挖掘 int

為了用事實說明挖掘機技術到底哪家強,PAT組織了一場挖掘機技能大賽。現請你根據比賽結果統計出技術最強的那個學校。

輸入格式:

輸入在第1行給出不超過105的正整數N,即參賽人數。隨後N行,每行給出一位參賽者的信息和成績,包括其所代表的學校的編號(從1開始連續編號)、及其比賽成績(百分制),中間以空格分隔。

輸出格式:

在一行中給出總得分最高的學校的編號、及其總分,中間以空格分隔。題目保證答案唯一,沒有並列。

輸入樣例:

6
3 65
2 80
1 100
2 70
3 40
3 0

輸出樣例:

2 150

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3
#include<string.h> 4 5 struct Node 6 { 7 int name; 8 int score; 9 }school[100002]; 10 11 int cmp( const void *a, const void *b) 12 { 13 struct Node *c = ( struct Node *)a; 14 struct Node *d = ( struct Node *)b; 15 return d->score-c->score; 16 } 17 int main() 18 {
19 int n,m; 20 int name,score; 21 scanf("%d",&n); 22 m = n; 23 while( n-- ) 24 { 25 scanf("%d%d",&name,&score); 26 school[name].name = name; 27 school[name].score += score; 28 } 29 qsort( school+1,m,sizeof(school[0]),cmp); 30 printf("
%d %d",school[1].name,school[1].score); 31 return 0; 32 }

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