struct Node
{
int cnt;
Node *next[26];
bool exist;
Node()
{
cnt = 0;
memset(next,0,sizeof(next));
exist = false;
}
}*rt;
void Insert(string str)
{
int a;
Node *p = rt;
int i = 0;
while(str[i]!='\0')
{
a = str[i] - 'a';
if(p->next[a] == NULL)
{
p->next[a] = new Node;
p->next[a]->cnt = 0;
}
p = p->next[a];
p->cnt += 1;
++i;
}
p->exist = true;
}
int QueryCnt(string str)
{
int a;
Node *p = rt;
int i = 0;
while(str[i] && p!=NULL)
{
a = str[i] - 'a';
p = p->next[a];
++i;
}
if(p == NULL)
return 0;
else
return p->cnt;
}
bool Queryword(string str)
{
int a;
Node *p = rt;
int i = 0;
while(str[i] && p!=NULL)
{
a = str[i] - 'a';
p = p->next[a];
++i;
}
if(p == NULL)
return 0;
if(p->exist==false)
return 0;
return true;
}