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 aaaaaa1b at 2008-07-07 16:02:24 on Problem 2945
这个程序在1002能过 为什么在这就不行了呢?
#include<stdio.h>
int count[20001]={0};
struct node
{
   char key[25];
   int num;
   struct node *left_child;
   struct node *right_child;
};
typedef struct node BiTreeNode;
typedef struct node* BiTree;
int SearchBST(BiTree T,char key[25],BiTree f,BiTree *p)
{
    if(!T){*p=f;return 0;}
    else if(strcmp(key,T->key)==0) {*p=T;return 1;}
    else if(strcmp(key,T->key)<0) return SearchBST(T->left_child,key,T,p);
    else if(strcmp(key,T->key)>0) return SearchBST(T->right_child,key,T,p);
}
int InsertBST(BiTree *T,char key[25])
{
    BiTree s=NULL,p=NULL;
    if(!SearchBST(*T,key,NULL,&p))
    {
       s=(BiTree)malloc(sizeof(BiTreeNode));
       strcpy(s->key,key);s->num=1;
       s->left_child=NULL;
       s->right_child=NULL;
       if(!p) (*T)=s;
       else if(strcmp(key,p->key)<0) p->left_child=s;
       else if(strcmp(key,p->key)>0) p->right_child=s;
    }
    else
        p->num++;
    return 1;
}
int Free(BiTree T)
{
    if(!T)
       return 0;
    if(T->left_child!=NULL)
       Free(T->left_child);
    if(T->right_child!=NULL)
       Free(T->right_child);
    free(T);
    return 1;
}
int InOrderTre(BiTree T)
{
    if(!T)
       return 0;
    if(T->left_child)
       InOrderTre(T->left_child);
    count[T->num]++;
    if(T->right_child)
       InOrderTre(T->right_child);
    return 1;
}
main()
{
      char key[25];
      int i,m,n;
      BiTree T=NULL;
      while(scanf("%d %d",&n,&m)!=EOF&&(m!=0&&n!=0))
      {
         for(i=1;i<=n;i++)
         {
            scanf("%s",key);
            InsertBST(&T,key);
         }
         InOrderTre(T);
         for(i=1;i<=n;i++)
         {
            printf("%d\n",count[i]);
            count[i]=0;
         }
         Free(T);
      }
      system("pause");
      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