题意:
给一组单词 开始提问每次给一个串求该串是上面几个单词的前缀
分析:
没给数据规模,但用链表写ME好几次,又用数组写开小RE了,试了几次才过了,真是醉了。。。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 500100
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
struct Trie{
int ch[N][];
int val[N],num;
void init(){
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
num=;
}
void build(char *s){
int u=,len=strlen(s);
for(int i=;i<len;++i){
int v=s[i]-'a';
if(!ch[u][v]){
memset(ch[num],,sizeof(ch[num]));
ch[u][v]=num++;
}
u=ch[u][v];
val[u]++;
}
}
int query(char *s){
int u=,len=strlen(s);
for(int i=;i<len;++i){
int v=s[i]-'a';
if(!ch[u][v])return ;
u=ch[u][v];
}
return val[u];
}
}trie;
int main()
{
char str1[],str2[];
trie.init();
while(gets(str1)&&str1[]!='\0')
trie.build(str1);
while(scanf("%s",str2)!=EOF){
printf("%d\n",trie.query(str2));
}
return ;
}