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 09:48:48 on Problem 2153
#include <iostream>
#include <cstdlib>
using namespace std;
struct student
{
	int score;
	char name[31];
};
int compare (const void * a, const void * b)
{
  return ( ((student*)a)->score < ((student *)b)->score);
}
int main()
{
	int n;
	cin>>n;
	char s[31];
	int i,j;
	char ch=getchar();
	for(i=0;i<n;++i)
		gets(s);
    int test;
	cin>>test;
	
	while(test--)
	{ 
	    int target;
		student str[10001];
		for(i=0;i<n;++i)
		{		
			cin>>str[i].score;
			char c=getchar();
			gets(str[i].name);
			if(strcmp(str[i].name,"Li Ming")==0)
				target=str[i].score;
		}	
        qsort (str, n, sizeof(student), compare);		
		for(i=0;i<n;++i)
			if(str[i].score==target && strcmp(str[i].name,"Li Ming")==0)			
				j=i;					
		i=j;
        while(i>=0)
		{
			int t=i-1;
			if(t<0)
			{
				cout<<1<<endl;
				break;
			}
			if(str[i].score==str[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