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

Re:高手看请下错哪啦

Posted by silentwind at 2008-07-13 15:01:01 on Problem 2021
In Reply To:高手看请下错哪啦 Posted by:ecjtujiangyj at 2007-07-27 16:48:59
> #include<stdio.h>
> #include<string.h>
> #include<stdlib.h>
> struct node
> {
>    char father[50];
>    char child[50];
>    int xage;
>    int age;       
> };
> node a[101];
> bool flag[101];
> int n;
> void recur(int p,int s)
> {
>    int i;
>    flag[p]=1;
>    a[p].age=s-a[p].xage;
>    s=a[p].age;
>    for(i=1;i<=n;i++)if(!flag[i]&&strcmp(a[i].father,a[p].child)==0) recur(i,s);      
> }
> int fun(void const *x,void const *y)
> {
>    node s,t;
>    s=*(node*)x;t=*(node*)y;
>    return t.age-s.age;
> }
> int main()
> {
>    int i,j,k,s,t;
>    char fa[50];
>    scanf("%d",&t);
>    for(k=1;k<=t;k++)
>    {
>       scanf("%d",&n);
>       for(i=1;i<=n;i++)
>       {
>          scanf("%s%s%d",a[i].father,a[i].child,&a[i].xage);
>          flag[i]=0;                
>       }
>       strcpy(fa,"Ted");s=100;
>       for(i=1;i<=n;i++)if(!flag[i]&&strcmp(a[i].father,fa)==0) recur(i,s);
>       qsort(a+1,n,sizeof(a[1]),fun);
>       printf("DATASET %d\n",k);
>       for(i=1;i<=n;i++)printf("%s %d\n",a[i].child,a[i].age);
>                   
>    }  
> }
当年龄相等时,没按字典序

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