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 200892458 at 2009-05-01 16:36:16 on Problem 2021
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
struct people
{
	char father[100];
	char child[100];
	int bornage;
}a[1100];
struct name
{
	char pepname[100];
	int age;
}b[1100];
bool cmp(const name &n1,const name &n2)
{
	if(n1.age==n2.age)
		return (strcmp(n1.pepname,n2.pepname)<0);
	return n1.age>n2.age;
}
int main()
{
	int k,rel,i,j,n;
	int cases=1;
	scanf("%d",&rel);
	while(rel--)
	{
		scanf("%d",&n);
		k=0;
		strcpy(b[0].pepname,"Ted");
		b[0].age=100;
		for(i=1;i<=n;i++)
		{
			scanf("%s%s%d",a[i].father,a[i].child,&a[i].bornage);
			if(strcmp(a[i].father,"Ted")==0)
			{
				strcpy(b[++k].pepname,a[i].child);
                b[k].age=100-a[i].bornage;
			}
		}
		printf("DATAAET %d\n",cases++);
		for(j=1;j<=n;j++)
		   for(i=1;i<=n;i++)
		   {
			   if(strcmp(b[j].pepname,a[i].father)==0)
			   { 
				   strcpy(b[++k].pepname,a[i].child);
                   b[k].age=abs(b[j].age-a[i].bornage);
			   }
		   }
		 sort(b+1,b+k+1,cmp);
		 cout<<b[1].pepname<<" "<<b[1].age<<endl;
		 for(i=2;i<=k;i++)
			 if(strcmp(b[i].pepname,b[i-1].pepname)!=0)
				  cout<<b[i].pepname<<" "<<b[i].age<<endl;
	}
	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