杭电的比赛 P-F水题
View Code
1 #include<stdio.h>//注意细节 2 #include<string.h> 3 #include<stdlib.h> 4 5 int cmp(const void *a,const void *b) 6 { 7 return *(int *)a - *(int *)b; 8 } 9 10 int main() 11 { 12 int i,j,ncases,N; 13 int a[55],b[55],k,c; 14 15 scanf("%d",&ncases); 16 17 memset(a,0,sizeof(a)); 18 memset(b,0,sizeof(b)); 19 for(i=1; i<=ncases; i++) 20 { 21 scanf("%d",&N); 22 for(j=0; j<N; j++) 23 { 24 scanf("%d",&c); 25 a[j] = c; 26 } 27 28 k = 0; 29 qsort(a,N,sizeof(a[0]),cmp); 30 for(j=1; j<=N-1; j++) 31 { 32 b[k++] = a[j]-a[j-1]; 33 } 34 qsort(b,k,sizeof(b[0]),cmp); 35 printf("Class %d\n",i); 36 printf("Max %d, Min %d, Largest gap %d\n",a[N-1],a[0],b[k-1]); 37 } 38 // system("pause"); 39 return 0; 40 } 41