模板题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
struct node
{
int cnt;
struct node *next[26];
node()
{
cnt = 0;
memset(next,0,sizeof(next));
}
};
node *root = NULL;
void buildtrie(char *s)
{
node *p = root;
node *tmp = NULL;
int len = strlen(s);
for(int i = 0; i <= len - 1; i++)
{
if(p->next[s[i] - 'a'] == NULL)
{
tmp = new node;
p->next[s[i] - 'a'] = tmp;
}
p = p->next[s[i] - 'a'];
p->cnt ++;
}
}
void findtrie(char *s)
{
node *p = root;
int len = strlen(s);
for(int i = 0; i <= len - 1; i++)
{
if(p->next[s[i] - 'a'] == NULL)
{
cout << 0 << endl;
return ;
}
p = p -> next[s[i]-'a'];
}
cout << p->cnt <<endl;
}
int main()
{
char str[11];
root = new node;
while(gets(str))
{
if(strcmp(str,"") == 0)
{
break;
}
buildtrie(str);
}
while(scanf("%s",str) != EOF)
{
findtrie(str);
}
return 0;
}