2012 新年A的第一道题目。纪念一下。
水题: 有m个东西要n个人评价给分,求出k个人的评价给分最高
View Code
#include#include #include #include using namespace std; #define MAXN 1000 struct node { double val; int num; }tagp[MAXN]; bool cmp1(node a,node b) { return a.val>b.val; } bool cmp2(int a,int b) { return a>b; } int arry[MAXN]; int main() { int n,m,k,i,j; double val; while (~scanf("%d %d %d",&n,&m,&k)) { memset(tagp,0,sizeof(tagp)); for (i = 0; i < m; ++i) tagp[i].num = i; for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) { scanf("%lf",&val); tagp[j].val += val; } } sort(tagp,tagp + m,cmp1); for (i = 0; i < k; i++) { arry[i] = tagp[i].num+1; } sort(arry,arry + k,cmp2); for (i = 0; i < k-1; ++i) printf("%d ",arry[i]); printf("%d\n",arry[i]); } return 0; }