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
}
查看全文
相关阅读:
关于Web服务器时间修改后遗症
C# MVC Api无法获得参数
C# MVC 全局错误Application_Error中处理(包括Ajax请求)
C# MVC 中自定义权限特性[Authorize]中对于Ajax访问的处理
ClosedXML、DocumentFormat.OpenXml导出DataTable到Excel
Visual Studio 2017中使用gulp编译sass/scss
VSCode 常用技巧总结
Chrome 和 IE 在box-sizing 设置不同的值的表现
c# 结构体
c# DefualtValue 常见问题
原文地址:https://www.cnblogs.com/Knuth/p/1562612.html
最新文章
Entity Framework 6 Code First的简单使用和更新数据库结构
ASP.NET MVC自定义Numberic属性的验证信息
C#中的异步编程--探索await与async关键字的奥妙之处,原来理解和使用异步编程可以这么简单
C#使用互斥量(Mutex)实现多进程并发操作时多进程间线程同步操作(进程同步)的简单示例代码及使用方法
C#使用读写锁三行代码简单解决多线程并发写入文件时线程同步的问题
ASP.NET中使用DropDownList实现无刷新二级联动详细过程
使用innerHTML获取HTML代码时,HTML标记属性的双引号好多都消失不见了,原来是属性值中包含空格才会保留双引号
SQLServer根据不同前缀生成多套流水号
ASP.NET文本框密码赋默认值的方法
C#使用 UdpClient 类进行简单通信的例子
热门文章
TCP和UDP之间的区别
C#如何获取CPU处理器核心数量
开启WIndows10 未经身份验证的来宾访问策略以及SMB1
EF框架之数据迁移
EF Core数据迁移操作步骤
redis、memcached、mongoDB 对比
C#MVC实现为雇员配置角色(完整详细+数据库)
C# 如何获取日期时间各种方法
【Asp.net】 七大内置对象
C#MVC用ZXing.Net生成二维码/条形码
Copyright © 2011-2022 走看看