hdu1251 统计难题(字典树)
来源:互联网 发布:自动释放内存软件 编辑:程序博客网 时间:2024/04/29 14:32
#include <iostream>
#include <string>
using namespace std;
struct node
{
bool isWord;
int next[26],cnt;
}tree[1000010];
string word;
int total;
void init(int i)
{
int k(0);
while (k<26)
tree[i].next[k++]=0;
tree[i].cnt=0;
tree[i].isWord = false;
return ;
}
void insert()
{
int len = word.size();
int i,k;
int nxt;
for (i=k=0;i<len;k=nxt,++i)
{
nxt = tree[k].next[word[i]-'a'];
if (!nxt) tree[k].next[word[i]-'a'] = nxt =++total;
++tree[nxt].cnt;
}
}
int find()
{
int i;
int len = word.size();
int nxt;
int k;
for (i=0,k=0;i<len;k=nxt,++i)
{
nxt = tree[k].next[word[i]-'a'];
if (!nxt) return 0;
}
return tree[k].cnt;
}
int main()
{
total=0;
while (getline(cin,word)&&word!="")
insert();
while (cin>>word)
cout<<find()<<endl;
return 0;
}
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树模版)
- HDU1251 统计难题(字典树模板)
- HDU1251统计难题(字典树模板)
- HDU1251 统计难题(字典树)
- 统计难题(hdu1251,字典树)
- hdu1251 统计难题 (字典树查找)
- hdu1251统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251 统计难题(字典树)
- HDU1251-统计难题(字典树)
- hdu1251 统计难题 字典树
- 【字典树】 hdu1251 统计难题
- hdu1251 统计难题(字典树)
- 统计难题(hdu1251字典树)
- 动态库在不同操作系统中的不同意义
- 数据结构与算法C#语言描述第12章二叉树
- C/C++程序编译步骤详解
- linux分类驱动对字符设备框架压力的卸载
- 网络日志(2010.6.17)
- hdu1251 统计难题(字典树)
- 数据结构与算法C#语言描述第14章高级排序算法
- Linux VSFTPD 基础配置
- J2ME下漫游(追逐)AI的实现
- 千元Android 3G手机普及是场梦
- blog
- Linux VSFTPD 进阶配置——虚拟用户
- C、C++语言语言编译过程总结详解
- J2ME下的手机游戏的优化