#include <stdio.h>
#include <stdlib.h>
typedef struct BSTNode
{
int data;
struct BSTNode *lchild,*rchild;
}BSTNode,*PNode;
int count = 0;
bool SearchBST(PNode T,int data)
{
count++;
if(T == NULL)
{
return false;
}
else if(data < T->data)
{
return SearchBST(T->lchild,data);
}
else if(data > T->data)
{
return SearchBST(T->rchild,data);
}
else
{
return true;
}
}
//向树中插入节点,若此节点在不在树中则插入,已在树中则不插入
PNode insertBST(int data,PNode root)
{
if(root == NULL)
{
root = (PNode)malloc(sizeof(BSTNode));
root->data = data;
root->lchild = NULL;
root->rchild = NULL;
return root;
}
if(data < root->data)
{
root->lchild = insertBST(data,root->lchild);
}
else if(data > root->data)
{
root->rchild = insertBST(data,root->rchild);
}
return root;
}
int main(){
int r[10000];
int i,j;
PNode root;
PNode current;
int search;
while(true){
for(i=0;i<10000;i++){
scanf("%d",&r[i]);
if(getchar()=='\n')
{
break;
}
}
scanf("%d",&search);
root = NULL;
current= NULL;
count = 0;
for(j=0;j<i;j++){
current = insertBST(r[j],current);
if(j == 0)
{
root = current;
}
}
SearchBST(root,search);
printf("%d",count);
if (getchar()=='\n')
{
printf("\n");
continue;
}
else
{
break;
}
}
return 0;
}