Hdu1251 - 统计难题 - 字典树
来源:互联网 发布:曲面软件 编辑:程序博客网 时间:2024/06/05 00:09
#include<stdio.h>#include<string.h>struct tree{int count;tree *next[30];tree(){count=0;for(int i=0;i<26;i++){next[i]=NULL;}}}*root;void build(char *word){tree *item=root;for(int i=0;word[i]!=NULL;i++){int j=word[i]-'a';if(item->next[j]==NULL){item->next[j]=new tree;}item=item->next[j];item->count++;}}int find(char *word){tree *item=root;for(int i=0;word[i]!=NULL;i++){int j=word[i]-'a';if(item->next[j]==NULL){return 0;}item=item->next[j];}return item->count;}int main(){root=new tree;char word[30];while(gets(word)!=NULL){if(strlen(word)==0){break;}build(word);}while(gets(word)!=NULL){printf("%d\n",find(word));}}
0 0
- hdu1251 统计难题 字典树
- 【字典树】 hdu1251 统计难题
- hdu1251 统计难题(字典树)
- 统计难题(hdu1251字典树)
- hdu1251 统计难题 (字典树)
- HDU1251统计难题(字典树)
- hdu1251统计难题(字典树)
- Hdu1251 - 统计难题 - 字典树
- hdu1251 统计难题 【字典树】
- HDU1251 统计难题【字典树】
- 【字典树】HDU1251统计难题
- hdu1251 统计难题 字典树
- hdu1251 统计难题 字典树
- hdu1251统计难题+字典树
- HDU1251 统计难题【字典树】
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树)
- HDU1251 统计难题 解题报告--字典树
- C语言字符串反转函数
- 【POJ】2771 Guardian of Decency 最大独立集
- SharpZipLib实现压缩多个文件或整个目录
- hash
- HDU 3342
- Hdu1251 - 统计难题 - 字典树
- Hibernate Validation各注解
- Copy Properties Maintain Their Own Copies
- poj3080~KMP+枚举
- JADE框架搭建
- MFC显示JPG图片
- c++ 将程序锁定到任务栏
- IE11 开发人员工具
- 勾股定理 (公式转换) 三个数互质(公式)