#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct T
{
    T *ch[26];
    int n,flag;
}rt;
char in[15];
void init(T *t)
{
    for(int i=0;i<26;i++)
    {
       t->ch[i]=NULL;
    }
    t->n=t->flag=0;
}
void insert(T *t,char *in)
{
    if(*in)
    {
         if(t->ch[*in-'a']==NULL)
         {
             t->ch[*in-'a']=(T *)malloc(sizeof(T));
             init(t->ch[*in-'a']);
         }
         (t->ch[*in-'a']->n)++;
         insert(t->ch[*in-'a'],in+1);
    }
    else
    {
        t->flag=1;    
    }
}
int find(T *t,char *in)
{
    if(t->ch[*in-'a']!=NULL)
    {
         if(*(in+1)=='\0')
         {
             return t->ch[*in-'a']->n;
         }
         else
         {
             return find(t->ch[*in-'a'],in+1);
         }
    }
    else
    {
         return 0;
    }
}
int main()
{
    T *s;
    s=(T *)malloc(sizeof(T));
    init(s);
    while(gets(in))
    {
        if(strlen(in)==0)
           break;//空行代表单词表的结束,以此来控制。 
        insert(s,in);
    }
    while(scanf("%s",in)!=EOF)
    {
        printf("%d\n",find(s,in));
    }
    //system("pause");
    return 0;
}
posted on 2011-05-28 10:37  枫叶飘泪  阅读(187)  评论(0编辑  收藏  举报