标签:des style color os io 文件 数据 for
banana band bee absolute acm ba b band abc
2 3 1 0
#include<iostream>
# include<cstring>
#include<cstdio>
using namespace std;
const int maxn=500000;
char wen[20];
struct node{
int tot;
int child[26]; //储存子节点,最多为26个;
node()
{
tot=0;
memset(child,0,sizeof(child));
}
}tree[maxn];
int sz=0;
void insert(char *s)
{
int u=0;
int h=strlen(s);
for(int i=0;i<h;i++)
{
int pos=s[i]-'a';
if(tree[u].child[pos]==0)
tree[u].child[pos]=++sz;
u=tree[u].child[pos]; // 将子节点作为母结点,往下走;
tree[u].tot++;
}
}
int find(char *t)
{
int u=0;
int h=strlen(t);
for(int i=0;i<h;i++)
{
int pos=t[i]-'a';
if(tree[u].child[pos]==0)
return 0;
u=tree[u].child[pos];
}
return tree[u].tot;
}
int main()
{
while(gets(wen))
{
if(strlen(wen)==0) break;
insert(wen);
}
while(gets(wen))
{
printf("%d\n",find(wen));
}
return 0;
}
标签:des style color os io 文件 数据 for
原文地址:http://blog.csdn.net/u013514722/article/details/38436817