算法與程序--游戲與玩樂
一個新程序員在計算技術上的學習經驗
C++博客
|
首頁
|
發新隨筆
|
發新文章
|
聯系
|
聚合
|
管理
隨筆:142 文章:0 評論:37 引用:0
pku-2001
字典樹的一個應用,地址:
http://acm.pku.edu.cn/JudgeOnline/problem?id=2001
#include
<
stdio.h
>
#include
<
string.h
>
struct
{
int
next[
26
];
int
c[
26
];
int
flag;
}
trie[
35000
];
int
now;
void
initt ()
{
now
=
0
;
for
(
int
i
=
0
; i
<
26
; i
++
)
{
trie[now].next[i]
=
0
;
trie[now].c[i]
=
0
;
}
trie[now].flag
=
0
;
now
++
;
}
int
add ()
{
for
(
int
i
=
0
; i
<
26
; i
++
)
{
trie[now].next[i]
=
0
;
trie[now].c[i]
=
0
;
}
trie[now].flag
=
0
;
now
++
;
return
now
-
1
;
}
int
ser (
char
*
str )
{
int
pre
=
0
;
while
(
*
str
!=
0
)
{
int
addr
=
*
str
-
'
a
'
;
if
(
!
trie[pre].next[addr] )
{
return
0
;
}
pre
=
trie[pre].next[addr];
str
++
;
}
if
(
!
trie[pre].flag )
{
return
0
;
}
return
pre;
}
int
ins (
char
*
str )
{
int
pre
=
0
;
while
(
*
str
!=
0
)
{
int
addr
=
*
str
-
'
a
'
;
if
(
!
trie[pre].next[addr] )
{
trie[pre].next[addr]
=
add ();
}
trie[pre].c[addr]
++
;
pre
=
trie[pre].next[addr];
str
++
;
}
trie[pre].flag
=
1
;
return
pre;
}
void
check (
char
*
str )
{
char
*
s
=
str;
int
pre
=
0
;
while
(
*
str
!=
0
)
{
int
addr
=
*
str
-
'
a
'
;
if
( trie[pre].c[addr]
==
1
)
{
while
( s
<=
str )
{
printf (
"
%c
"
,
*
s );
s
++
;
}
printf (
"
\n
"
);
return
;
}
pre
=
trie[pre].next[addr];
str
++
;
}
printf (
"
%s\n
"
, s );
}
char
str[
1005
][
25
];
int
main ()
{
char
in[
25
];
int
n
=
0
;
initt ();
while
( scanf (
"
%s
"
, in )
!=
EOF )
{
int
len
=
strlen ( in );
if
( len )
{
strcpy ( str[n
++
], in );
if
(
!
ser ( in ) )
{
ins ( in );
}
}
}
for
(
int
i
=
0
; i
<
n; i
++
)
{
printf (
"
%s
"
, str[i] );
check ( str[i] );
}
return
0
;
}
發表于 2008-04-09 12:47
ghbxx
閱讀(225)
評論(0)
編輯
收藏
引用
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
<
2008年4月
>
日
一
二
三
四
五
六
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
公告
決定從線程開始!!
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
(6)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2009年3月 (1)
2008年12月 (1)
2008年9月 (1)
2008年8月 (6)
2008年7月 (11)
2008年6月 (49)
2008年4月 (40)
2008年3月 (33)
搜索
最新評論
1.?re: pku-1811
樓主啊,稍微改一下你的代碼咋就錯了。不用miller labin直接用費馬定理原來的寫不是錯就超時啊
--re
2.?re: pku-1811
hugeint product_mod(hugeint A, hugeint B, hugeint C)
這個函數中, D = (D + D) % C; 應該錯了吧。
--re
3.?re: pku-1338
牛逼
--CAT
4.?re: pku-3159
好復雜啊。。。
--搜咯翻車魚
5.?re: pku-1001(1)
大數模板啊 要是能支持小數就好了 O(∩_∩)O~
--abilitytao
閱讀排行榜
1.?RFC-1321MD5算法(1511)
2.?SCOKS4協議及其改進(1485)
3.?RFC1929-SCOKS V5的用戶名/密碼認證方式(1480)
4.?RFC977-網絡新聞組協議文檔(1468)
5.?RFC1928-SCOKS V5協議(1338)
評論排行榜
1.?大家好,這是一個程序和算法薈萃的地方(4)
2.?pku-1338(4)
3.?pku-1811(3)
4.?pku-1723(3)
5.?pku-2002(3)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 ghbxx
国产成人久久777777
|
男女久久久国产一区二区三区
|
久久久一本精品99久久精品66
|
久久久久人妻一区精品色
|
人妻无码久久精品
|
亚洲v国产v天堂a无码久久
|
少妇人妻88久久中文字幕
|
久久免费小视频
|
久久精品国产免费观看三人同眠
|
国产韩国精品一区二区三区久久
|
亚洲伊人久久大香线蕉苏妲己
|
亚洲一级Av无码毛片久久精品
|
a高清免费毛片久久
|
日本加勒比久久精品
|
国产欧美一区二区久久
|
久久夜色精品国产亚洲
|
国产精品欧美久久久久无广告
|
国产成人久久精品一区二区三区
|
激情久久久久久久久久
|
国产精品99久久精品
|
亚洲中文字幕无码久久精品1
|
久久久久久国产精品免费免费
|
久久99国内精品自在现线
|
久久无码国产专区精品
|
久久福利片
|
久久www免费人成精品香蕉
|
国产一级持黄大片99久久
|
久久精品水蜜桃av综合天堂
|
色青青草原桃花久久综合
|
久久久国产一区二区三区
|
精品多毛少妇人妻AV免费久久
|
91久久香蕉国产熟女线看
|
精品久久久久久综合日本
|
国产午夜精品久久久久免费视
|
久久亚洲精品成人av无码网站
|
久久九九兔免费精品6
|
久久只有这里有精品4
|
久久久精品国产
|
久久精品国产AV一区二区三区
|
久久久久久精品免费免费自慰
|
久久国产欧美日韩精品
|