http://acm.hdu.edu.cn/showproblem.php?pid=1031
水题不解释,之前看错题意。
View Code
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 struct Node 5 { 6 int number; 7 double satisfy; 8 }node[1010]; 9 int cmp1(const void*x,const void*y) 10 { 11 struct Node *aa=(struct Node*)x; 12 struct Node *bb=(struct Node*)y; 13 if(aa->satisfy==bb->satisfy) 14 return aa->number-bb->number; 15 return bb->satisfy-aa->satisfy; 16 } 17 int cmp2(const void*x,const void*y) 18 { 19 return *(int*)y-*(int*)x; 20 } 21 int main() 22 { 23 int n,m,k; 24 int i,j; 25 double xx; 26 while(~scanf("%d%d%d",&n,&m,&k)) 27 { 28 29 memset(node,0,sizeof(node)); 30 for(i=0;i<n;i++) 31 { 32 for(j=0;j<m;j++) 33 { 34 scanf("%lf",&xx); 35 node[j].satisfy+=xx; 36 node[j].number=j+1; 37 } 38 } 39 qsort(node,m,sizeof(node[0]),cmp1); 40 qsort(node,k,sizeof(node[0]),cmp2); 41 for(i=0;i<k-1;i++) 42 printf("%d ",node[i].number); 43 printf("%d\n",node[k-1].number); 44 45 } 46 }