C語言源碼: [cpp] #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct Bitree { int data; struct Bitree *lchild,*rchild; }Bitree; Bitree *create(Bitree *t,int n) { Bitree *p,*q; p=(Bitree *)malloc(sizeof(Bitree)); p->data=n; p->lchild=NULL; p->rchild=NULL; if(!t) t=p; else { q=t; while((q->data>n&&q->lchild)||(q->data<n&&q->rchild)) { if(q->data>n) q=q->lchild; else q=q->rchild; } if(q->data>n) q->lchild=p; else q->rchild=p; } return t; } void Pre(Bitree *t,int a[],int *n) { int m=*n; if(t) { *(a+m)=t->data; m++; *n=m; Pre(t->lchild,a,n); Pre(t->rchild,a,n); } } int main() { int n,a[11],b[11],i,len,j,k,*num; char s[11]; Bitree *T,*t; scanf("%d",&n); while(n) { k=0; num=&k; T=NULL; getchar(); scanf("%s",s); getchar(); len=(int)strlen(s); for(i=0;i<len;i++) T=create(T,s[i]-'0'); Pre(T,a,num); for(j=1;j<=n;j++) { k=0; t=NULL; num=&k; scanf("%s",s); getchar(); for(i=0;i<len;i++) t=create(t,s[i]-'0'); Pre(t,b,num); for(i=0;i<len;i++) if(a[i]!=b[i]) break; if(i==len) printf("YES\n"); else printf("NO\n"); } www.2cto.com scanf("%d",&n); } }