此题的思路简单,从上到下进行模拟,该定义的定义,该输入的输入,该输出的输出;
最重要的是,该用结构体的一定要用结构体!!!!!!!
此题的坑在于,我用c++写的代码怎么都是WA,但是我只是简单的把输入输出换成c语言printf和scanf,就AC掉,,,,,,无天理
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct student { char num[100]; int sum_s; }; int cmp(const void *a,const void *b) { student at=*(student*)a; student bt=*(student*)b; if (bt.sum_s==at.sum_s) return strcmp(at.num,bt.num); //return at.num.compare(bt.num); else return bt.sum_s-at.sum_s; } int queue[6]; int main() { student stu[1000]; int N,M,G; while(scanf("%d",&N)!=EOF) { if(N==0) break; else { scanf("%d %d",&M,&G); int s_count; int i=0,j=0; for (i=1;i<=M;i++) scanf("%d",&queue[i]); for (i=0;i<N;i++) { scanf("%s %d",&stu[i].num,&s_count); int tem_sum=0; int tem; stu[i].sum_s=0; for (j=0;j<s_count;j++) { scanf("%d",&tem); tem_sum+=queue[tem]; } stu[i].sum_s=tem_sum; } qsort(stu,N,sizeof(student),cmp); int count=0; for (i=0;i<N;i++) { if (stu[i].sum_s>=G) count++; } printf("%d ",count); for (i=0;i<N;i++) if (stu[i].sum_s>=G) printf("%s %d ",&stu[i].num,stu[i].sum_s); } } return 0; }