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

为什么WA?

Posted by sunflowwer at 2006-08-18 22:43:46 on Problem 2153
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student{
     int a;
	 int b;
}sort[100000];
int cmp(const void *a,const void *b)
{
     struct student *c=(student *)a;
	 struct student *d=(student *)b;
	 if(c->a==d->a)
		 return d->b-c->b;
	 return d->a-c->a;
}
int main()
{
    char *message="Li Ming";
	int i,j,l,m,n,v;
	char str[1000];char c;
	scanf("%d",&n);
	scanf("%c",&c);
	for(i=0;i<n;i++)
		gets(str);
	scanf("%d",&m);
	scanf("%c",&c);
	for(l=0;l<m;l++)
	{
		for(i=0;i<n;i++){
		    gets(str);
			for(sort[i].b=0,j=0;str[j];j++)
				if(str[j]==' '){
					if(strcmp(str+j+1,message)==0)
						sort[i].b=1;
				    break;
				}
		    sscanf(str,"%d",&v);
			if(!l)
			    sort[i].a=v;
			else if(l)
				sort[i].a+=v;
		}
		qsort(sort,n,sizeof(sort[0]),cmp);
		for(i=0;i<n;i++)
			if(sort[i].b){
			    printf("%d\n",i+1);
				break;
			}
	}
    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