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 JLKJ_ZHUSHAN at 2010-07-28 15:27:57 on Problem 2021
#include<stdio.h>
#include<string.h>

#define MAN 101

char son_n[MAN][20],dady_n[MAN][20];
int son_age[MAN],sonb[MAN];
int n,m;

int cal_age(char dady[])
{
	int i,j;
	int father_age,father_num;
	if(!strcmp(dady,"Ted"))
		return 100;
	else
	{
		for(i=1;i<=m;i++)
		{
			if(!strcmp(dady,son_n[i]))
			{
				father_age=son_age[i];
				father_num=i;
			}
		}
		if(father_age>0)
		{
			return father_age;
		}
		else
		{

			father_age=cal_age(dady_n[father_num])-sonb[father_num];
			return father_age;
		}
	}
}
void sort()
{
	int i,j;
	char temp_n[20];
	int temp;
	for(i=1;i<m;i++)
	{
		for(j=i+1;j<=m;j++)
		{
			if((son_age[i]<son_age[j])||(son_age[i]==son_age[j]&&strcmp(son_n[i],son_n[j])>1))
			{
				strcpy(temp_n,son_n[i]);
				strcpy(son_n[i],son_n[j]);
				strcpy(son_n[j],temp_n);
				temp=son_age[i];
				son_age[i]=son_age[j];
				son_age[j]=temp;
			}
		}
	}
}
int main()
{
	int i,j;


	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&m);
		for(j=1;j<=m;j++)
		{
			scanf("%s %s %d",dady_n[j],son_n[j],&sonb[j]);
		}
		for(j=1;j<=m;j++)
		{
			son_age[j]=cal_age(dady_n[j])-sonb[j];
		}
		sort(son_n,son_age);
		printf("DATASET %d\n",i);
		for(j=1;j<=m;j++)
		{
			printf("%s %d\n",son_n[j],son_age[j]);
		}
	}
	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