Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:已解决

Posted by zhanglinghao at 2015-08-05 09:27:26 on Problem 2153
In Reply To:Re:已解决 Posted by:kuaichenyang at 2015-08-04 10:49:51
> 你是怎么解决的,我也是用快排做的,帮我看看呗,大牛
> 
> 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator