#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1024;
int tree1[maxn],tree2[maxn];
void insert(char s,int *tree){
int t=1;
while(tree[t]!=-1){
if(s<tree[t])t=2*t;
else if(s>tree[t])t=2*t+1;
}
tree[t]=s;
}
void build(char *s,int *tree){
int len=strlen(s);
tree[1]=s[0]-'0';
for(int i=0;i<len;i++)insert(s[i],tree);
}
int main(){
int n;
while(scanf("%d",&n)==1 && n){
memset(tree1,-1,sizeof(tree1));
char s1[10],s2[10];
scanf("%s",s1);
build(s1,tree1);
for(int i=0;i<n;i++){
memset(tree2,-1,sizeof(tree2));
scanf("%s",s2);
build(s2,tree2);
int j;
for(j=1;j<maxn;j++)
if(tree1[j]!=tree2[j])break;
if(j==maxn)printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
HDU 3791 二叉搜索树 (基础题)
最新推荐文章于 2020-10-12 21:41:21 发布