#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
node *lchild,*rchild;
};
int flag;
node *creat(node *root,int x)
{
if(root == NULL)
{
root = new node();
root->lchild = NULL;
root->rchild = NULL;
root->data = x;
}
else
{
if(x>root->data)
root->rchild = creat(root->rchild,x);
else
root->lchild = creat(root->lchild,x);
}
return root;
}
node *creat2(char a[],int len)
{
int j=0;
node *t = new node();
while(j<len)
{
t = creat(t,a[j]-'0');
j++;
}
return t;
}
void panduan(node *t1,node *t2)
{
if(t1==NULL&&t2==NULL)
return ;
else if(t1==NULL||t2==NULL)
{
flag=0;
return ;
}
else if(t1->data!=t2->data)
{
flag=0;
return ;
}
panduan(t1->lchild,t2->lchild);
panduan(t1->rchild,t2->rchild);
}
int main()
{
char a[30];
char b[30];
int n;
while(cin>>n&&n!=0)
{
node *t1,*t2;
t1 = new node();
t2 = new node();
cin>>a;
int len = strlen(a);
while(n--)
{
cin>>b;
t1 = creat2(a,len);
t2 = creat2(b,len);
flag=1;
panduan(t1,t2);
if(flag==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
return 0;
}
二叉排序树
最新推荐文章于 2023-07-06 14:32:43 发布