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

各位大牛,请帮我看看哪错了

Posted by jlnu123 at 2008-11-01 11:43:01 on Problem 2153
#include <iostream>
#include <cstdlib>
using namespace std;
struct student
{
	int score;
	char name[31];
};
student s[10001];
int compare (const void * a, const void * b)
{
	if(((student *)a)->score==((student *)b)->score)
		return strcmp(((student *)a)->name,((student *)b)->name);
  return ( ((student*)a)->score < ((student *)b)->score);
}
int comp (const void * a, const void * b)
{
	
	return strcmp(((student *)a)->name,((student *)b)->name);
 
}
int bsch(student s[],int n,char str[])
{
	int l=0,r=n-1;
	if(strcmp(str,s[0].name)==0)
		return 0;
	while(l<r)
	{
		int m=(l+r+1)/2;
		if(strcmp(str,s[m].name)==0)
			return m;		
        else if(strcmp(str,s[m].name)<0)
			r=m-1;
		else if(strcmp(str,s[m].name)>0)
			l=m;
	}	
	return -1;
}
int main()
{
	int n;
	cin>>n;	
	int i,j,k;
	char ch=getchar();
	for(i=0;i<n;++i)
		gets(s[i].name);
 
    int test;
	cin>>test;	
	for(k=0;k<test;++k)
	{ 
		qsort(s,n,sizeof(student),comp);
	    int target;
		student str[10001];
		
		for(i=0;i<n;++i)
		{		
			cin>>str[i].score;
			char c=getchar();
			gets(str[i].name);
			int  p;
			p=bsch(s, n,str[i].name);
	
	    	s[p].score+=str[i].score;
			if(strcmp(str[i].name,"Li Ming")==0)
			{
				p=bsch(s, n,"Li Ming");
				target=s[p].score;
			}
		}

        qsort (s, n, sizeof(student), compare);	
  
		for(i=0;i<n;++i)
			if(s[i].score==target && strcmp(s[i].name,"Li Ming")==0)			
				j=i;					
		i=j;
        while(i>=0)
		{
			int t=i-1;
			if(t<0)
			{
				cout<<1<<endl;
				break;
			}
			if(s[i].score==s[t].score)
				--i;
			else
			{
				cout<<i+1<<endl;
				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