POJ 2503 Babelfish
2010-12-13 12:46
417 查看
解题思路:字典树
NULL
NULL
#include <iostream> using namespace std; #define MAXN 1000001 char dic[MAXN],word[MAXN][11],ch[11]; int size,first[MAXN],next[MAXN],place[MAXN]; void Build(int n) { int i,t,p=0,l=strlen(ch); for(i = 0; i<l;i++) { t=first[p]; while (t&&dic[t]!=ch[i])t=next[t]; if(!t) { dic[++size]=ch[i],next[size]=first[p]; first[p]=size,first[size]=0,p=size; } else p=t; } place[p]=n; } int main() { int i,t,p,l,n,size=n=0; char str[30]; while (gets(str)&&str[0]!='\0') sscanf(str, "%s %s",word[++n], ch),Build(n); while (gets(ch)&&ch[0]!='\0') { p=0,l=strlen(ch); for(i=0;i<l;i++){t=first[p];while (t&&dic[t]!=ch[i])t=next[t];p=t;} (p==0)?printf("eh\n"):printf("%s\n",word[place[p]]); } return 0; }
相关文章推荐
- POJ 2503 Babelfish [map & string]
- POJ2503 Babelfish(二分)
- poj 2503 Babelfish(字典树)
- POJ 2503 Babelfish (STL map的应用)
- POJ 2503 BABELFISH (HASH)
- Poj 2503 Babelfish(Map操作)
- Poj:2503 Babelfish
- poj 2503 Babelfish(字典树或STL水题) 解题报告(百炼2804)
- POJ 刷题系列:2503. Babelfish
- POJ 2503 Babelfish (Trie树)
- POJ 2503 Babelfish (Hash)
- POJ 2503 Babelfish
- POJ 2503:Babelfish(字典树入门)
- Poj 2503 Babelfish (Trie / STL / BKDR Hash)
- poj 2503 Babelfish
- Poj 2503 Babelfish(Map操作)
- POJ 2503 Babelfish
- 文章标题 POJ 2503 : Babelfish(字典树)
- POJ 2503-Babelfish
- poj - 2503 Babelfish