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
}
查看全文
相关阅读:
浏览器 显示一个对话框,对话框中包含一条文字信息,用来提示用户输入文字。window.prompt()
JS字符串转换为JSON对象的四种方法
js中 json对象与json字符串相互转换的几种方式 $.parseJSON(jsonStr)json字符串转换为json对象
C#变量命名规则(命名规范)
C#中AppDomain.CurrentDomain.BaseDirectory(获取程序的基目录)及各种路径获取方法
C# 的 Path.GetFileName、Path.GetExtension、Path.GetDirectoryName千一网络 http://www.itpow.com/
js计算两个时间相差天数,获取时间的毫秒数之差
C#将DataTable转化为List<T>
https://www.cnblogs.com/sizhizhiyue/p/4820973.html asp.net后台导出excel的方法一:使用response导出excel
.NET调用AS/400上的程序(.NET CALL AS/400 PGM)
原文地址:https://www.cnblogs.com/Knuth/p/1562612.html
最新文章
如何开展一个机器视觉项目
机器视觉项目流程
haclon机器视觉图像处理分析项目开发流程及选型需求分析
Pyramid Pooling Module (PPM)金字塔池化模型充分利用上下文信息
Faster RCNN网络理解
传统OCR的字符切割与识别
单片机,FPGA, 上位机
无人驾驶
生成对抗网络
CenterNet精读 https://github.com/xingyizhou/CenterNet
热门文章
关于相关系数
R语言的内存(小总结)
每日一题(泰勒级数)
每日一题(收敛级数)
浅谈16进制数
自己的提问。
查看appium参数
充分条件与必要条件
简单爬取一张图片
获得当前时间的毫秒级别datetime.now.tostring(yyyyMMddHHmmssfff)
Copyright © 2011-2022 走看看