posts - 20,  comments - 6,  trackbacks - 0

 

#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>
struct dictree  
{   
    
struct dictree *child[26];   
    
int n; 
}
;   
struct dictree *newnode()
{
 
int i;
    
struct dictree *t;
    t
=(struct dictree*)malloc(sizeof(struct dictree));
    t
->n=0;
    
for(i=0;i<26;i++)t->child[i]=NULL;
    
return t;
}

struct dictree *root; 
int main()
{
 
char a[1000],b[1000];
 
int i,j,k,l,n;
 
struct dictree *s=newnode(); 
 
//freopen("d:\\abc.txt","w",stdout);
 root=newnode();
 s
=root;
 
while(gets(a))
 
{
  
if(a[0]=='\0')
  
{
   
break;
  }

  l
=strlen(a);
  s
=root;
  
for(i=0;i<l;i++)
  
{
          n
=a[i]-'a';
        
if(s->child[n])
   s
=s->child[n];
        
else 
        
{
            s
->child[n]=newnode();
            s
=s->child[n];                       
        }
 
        s
->n++;
  }

 }

 k
=0;
 j
=0;
 
while(scanf("%s",b)!=EOF)
 
{
  
/*if(k)
  printf("\n");
  else
  k++;
*/

  j
=1;
  s
=root;
   
for(i=0;i<strlen(b);i++)
      
{
          n
=b[i]-'a';
         
if(s->child[n])
    s
=s->child[n];
         
else
         
{
          printf(
"0\n");
          j
=0;
          
break;
     }
 
  }

  
if(j)
  printf(
"%d\n",s->n);
 }

}


posted on 2009-01-18 22:20 混沌的云 阅读(149) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜