思路:这不是一颗裸的排序二叉树么...直接DFS就好啦
#include<bits/stdc++.h>
using namespace std;
struct Node
{
int data;
Node*lson;
Node*rson;
Node(){}
Node(int x)
{
data = x;
lson = rson = NULL;
}
};
void build(Node *root,int key)
{
if (key < root->data)
{
if (root->lson==NULL)
{
root->lson = new Node(key);
return;
}
else
build(root->lson,key);
}
else
{
if (root->rson == NULL)
{
root->rson = new Node(key);
return;
}
else
build(root->rson,key);
}
}
void get(Node*root,int key)
{
if (root->data==key)
{
puts("");
return;
}
else if (key<root->data)
{
putchar('E');
get(root->lson,key);
}
else
{
putchar('W');
get(root->rson,key);
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,rt;
scanf("%d",&n);
scanf("%d",&rt);
Node*root = new Node(rt);
for (int i = 1;i<n;i++)
{
int temp;
scanf("%d",&temp);
build(root,temp);
}
int q;
scanf("%d",&q);
while(q--)
{
int qq;
scanf("%d",&qq);
get(root,qq);
}
root=NULL;
}
}