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:快排水过~~~sort强大In Reply To:快排水过~~~sort强大 Posted by:kaitian521 at 2010-10-21 08:51:11 我也是用快排做的,就是过不了,是不是哪里有问题? 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