poj 2503 Babelfish 字典树
来源:互联网 发布:aws windows 2012 编辑:程序博客网 时间:2024/06/09 19:18
题目:就像查找一本字典,根据输入的条目和要查询的单词,给出查询结果(每个单词长度不超过10)。
分析:直接就是裸的字典树。听说还可以快排+二分或者hash之类的,但我懒得写了。
代码:
var str:string; i,a1,x,len:longint; a:array[1..1000000] of longint; w:array[1..1000000] of string; s:array[1..1000000] of char; son:array[1..1000000,1..26] of longint;procedure insert(x:longint;str,str1:string);var i:longint;begin if str='' then begin w[x]:=str1; exit; end; for i:=1 to a[x] do if s[son[x,i]]=str[1] then begin delete(str,1,1); insert(son[x,i],str,str1); exit; end; inc(a1); inc(a[x]); son[x,a[x]]:=a1; s[a1]:=str[1]; delete(str,1,1); insert(a1,str,str1);end;function find(x:longint;str:string):string;var i:longint;begin find:='eh'; if str='' then begin if w[x]<>'' then find:=w[x]; exit; end; for i:=1 to a[x] do if s[son[x,i]]=str[1] then begin delete(str,1,1); find:=find(son[x,i],str); exit; end;end;begin readln(str); a1:=1; while length(str)>=1 do begin x:=pos(' ',str); len:=length(str); insert(1,copy(str,x+1,len-x),copy(str,1,x-1)); readln(str); end; while not eof do begin readln(str); writeln(find(1,str)); end;end.
0 0
- poj 2503 Babelfish(字典树)
- poj 2503 Babelfish 字典树
- poj 2503 Babelfish(字典树)
- POJ 2503 Babelfish(字典树)
- poj-2503-Babelfish-字典树
- poj 2503 Babelfish(字典树)
- POJ 2503 - Babelfish(字典树)
- poj 2503 Babelfish 字典树
- POJ 2503-Babelfish【字典树】
- Babelfish+poj+字典树
- POJ 2503 Babelfish 字典树应用
- POJ 2503 Babelfish(字典树Trie)
- POJ - 2503 Babelfish 字典树做法
- POJ 2503 Babelfish(字典树)
- poj 2503 Babelfish(字典树)
- poj 2503 Babelfish(字典树·翻译)
- POJ - 2503 - Babelfish(字典树)
- POJ 2503 Babelfish 字典树入门题
- Java中的自动拆装箱
- 添加自定义的View视图类(自定义一个进度条)
- zookeeper 中的zoo_sample.cfg文件参数详解
- 浅谈C#委托
- 设计模式----观察者模式
- poj 2503 Babelfish 字典树
- [CodeVS1748] NOI2005 瑰丽华尔兹
- Python实现二路归并排序
- android-Working with System Permissions
- Notification
- KVO的底层实现
- 从贝叶斯定理说开去
- 148Sort List
- 安装OS X El Capitan后pod: command not found