zoukankan
html css js c++ java
字典树 模板
Code
1
//
字典树模板
2
#include
<
iostream
>
3
using
namespace
std;
4
const
int
kind
=
26
;
5
struct
node
6
{
7
int
i,count;
8
node
*
next[kind];
9
node()
10
{
11
count
=
1
;
12
for
(i
=
0
;i
<
kind;i
++
)
13
next[i]
=
NULL;
14
}
15
}
;
16
void
insert(node
*
root,
char
*
word)
17
{
18
int
i
=
0
,branch;
19
node
*
local
=
root;
20
if
(local
==
NULL)
21
{
22
local
=
new
node();
23
root
=
local;
24
}
25
while
(word[i])
26
{
27
branch
=
word[i]
-
'
a
'
;
28
if
(local
->
next[branch])
29
local
->
next[branch]
->
count
++
;
30
else
31
local
->
next[branch]
=
new
node();
32
i
++
;
33
local
=
local
->
next[branch];
34
}
35
}
36
int
search(node
*
root,
char
*
word)
37
{
38
int
i
=
0
,branch,ans;
39
node
*
local
=
root;
40
41
if
(local
==
NULL)
42
return
0
;
43
while
(word[i])
44
{
45
branch
=
word[i]
-
'
a
'
;
46
if
(
!
local
->
next[branch])
47
return
0
;
48
i
++
;
49
local
=
local
->
next[branch];
50
ans
=
local
->
count;
51
}
52
return
ans;
53
}
54
int
main()
55
{
56
char
str[
12
];
57
node
*
root
=
new
node;
58
while
(gets(str)
&&
strcmp(str,
""
))
59
insert(root,str);
60
while
(scanf(
"
%s
"
,str)
!=
EOF)
61
printf(
"
%d\n
"
,search(root,str));
62
return
0
;
63
}
查看全文
相关阅读:
拓端tecdat|R语言平滑算法LOESS局部加权回归、三次样条、变化点检测拟合电视节目《白宫风云》在线收视率
拓端tecdat|R语言结合新冠疫情COVID-19对股票价格预测:ARIMA,KNN和神经网络时间序列分析
拓端tecdat|Stata广义矩量法GMM面板向量自回归PVAR模型选择、估计、Granger因果检验分析投资、收入和消费数据
拓端tecdat|Python用T-SNE非线性降维技术拟合和可视化高维数据iris鸢尾花、MNIST 数据
confirmit中常用 短代码
DELL服务器硬件信息采集SHELL脚本
功能、资源权限管理的设计
maven--插件篇(assembly插件)
呀哈哈
virtualbox扩展硬盘容量
原文地址:https://www.cnblogs.com/Knuth/p/1562612.html
最新文章
C#.WinForm调用winapi SendMessage方法跨进程发消息
C#.WinForm 拖动文件到PictrueBox(支持跨UAC拖动)
C# 根据出生年月 计算天数/计算X岁X月X天字符串
hologres 配置
nginx 反向代理后,page内的链接没有进行相应的修改怎么做
共耗材料成本分配
SAP关联方跨公司交易的自动清帐与实现 转载(转)
新增采购订单锁定含税单价,只能走价目表(全局性设置)
劳动合同到期后不续签可以要求赔偿吗
敏捷开发
热门文章
SAP-FICO基础(3)
BSEG簇表
增强安卓手机续航的设置(亲测有用)
wcf纯代码实现http服务
拓端tecdat:R语言用加性多元线性回归、随机森林、弹性网络模型预测鲍鱼年龄和可视化
拓端tecdat:matlab数据可视化交通流量分析天气条件、共享单车时间序列数据
拓端tecdat:matlab用Logistic逻辑回归建模和马尔可夫链蒙特卡罗MCMC方法分析汽车实验数据
拓端tecdat:Python 用ARIMA、GARCH模型预测分析股票市场收益率时间序列
拓端tecdat|PYTHON贝叶斯推断计算:用BETA先验分布推断概率和可视化案例
拓端tecdat|R语言非线性混合效应 NLME模型(固定效应&随机效应)对抗哮喘药物茶碱动力学研究
Copyright © 2011-2022 走看看