Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:WHY!!!! WA?????? 哪里错了????In Reply To:WHY!!!! WA?????? 哪里错了???? Posted by:win1611 at 2010-02-02 16:54:12 我写的和你差不多,一起看看吧,不知道你后来过了没有 Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define Maxn 10005 typedef struct tagStudent { char name[35]; int score; int index; }Student; Student stu[Maxn],Temp[Maxn]; int n,m; int cmpName(const void *a,const void *b) { return strcmp(((Student *)a)->name,((Student *)b)->name); } int cmpSor(const void *a,const void *b) { return ((Student *)b)->score-((Student *)a)->score; } int main() { int i,pos; scanf("%d",&n); getchar(); for(i=0;i<n;i++) gets(stu[i].name); qsort(stu,n,sizeof(stu[0]),cmpName); for(i=0;i<n;i++) if(!strcmp(stu[i].name,"Li Ming")) { pos=i; break; } scanf("%d",&m); getchar(); while(m--) { int k=1; char input[100]; for(i=0;i<n;i++) { char *p=input; gets(input); sscanf(input,"%d",&Temp[i].score); while(p[0]!=' ') ++p; while(p[0]==' ') ++p; strcpy(Temp[i].name,p); } qsort(Temp,n,sizeof(Temp[0]),cmpName); for(i=0;i<n;i++) stu[i].score+=Temp[i].score; qsort(stu,n,sizeof(stu[0]),cmpSor); for(i=1,stu[0].index=1;i<n;i++) if(stu[i].score==stu[i-1].score) stu[i].index=k; else stu[i].index=++k; qsort(stu,n,sizeof(stu[0]),cmpName); printf("%d\n",stu[pos].index); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator