#include <bits/stdc++.h>
#define ElemType char
using namespace std;
ElemType arr[1123];
ElemType res[1123];
typedef struct BinaryTree
{
ElemType data;
struct BinaryTree *Left;
struct BinaryTree *Right;
}Node;
void BstCreat(Node *&root, ElemType x); ///建立二叉排序树
bool CmpBst(Node *root, Node *p); /// 比较二叉排序树
int main()
{
int n = 0;
while(cin >> n && n)
{
Node *root = new Node;
root = NULL; /// 二叉排序树初始化QAQ
cin >> arr;
int len = strlen(arr);
for(int i = 0; i < len; i++)
{
BstCreat(root, arr[i]); /// 建立文本二叉树
}
while(n--)
{
Node *p = new Node;
p = NULL; /// 二叉排序树初始化QAQ
cin >> res;
for(int i = 0; i < len; i++)
{
BstCreat(p, res[i]); /// 建立模式二叉树
}
int f = CmpBst(root, p);
if(!f)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
}
}
}
return 0;
}
void BstCreat(Node *&root, ElemType x) ///建立二叉排序树
{
if(!root)
{
root = new Node;
root->data = x;
root->Left = NULL;
root->Right = NULL;
}
else
{
if(x < root->data)
{
BstCreat(root->Left, x);
}
else
{
BstCreat(root->Right,x);
}
}
}
bool CmpBst(Node *root, Node *p) /// 比较二叉排序树
{
if(root == NULL && p == NULL)
{
return true;
}
else if(root == NULL || p == NULL)
{
return false;
}
else
{
if(root->data != p->data)
{
return false;
}
else if(CmpBst(root->Left, p->Left) && CmpBst(root->Right, p->Right))
{
return true;
}
}
return false;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交