HDU 1075 字典树裸
2011-04-25 14:10
260 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1075
题意:给你字符串以及它的映射,提问任意一个映射它真实的字符串是什么
注意所求的字符串只是某个字符串的前缀情况~~
题意:给你字符串以及它的映射,提问任意一个映射它真实的字符串是什么
注意所求的字符串只是某个字符串的前缀情况~~
#include<iostream> using namespace std; #define N 1000000 char ans [15]; int tree [26]; int Node; void init() { memset(tree[0],0,sizeof(tree[0])); Node=0; } void insert(char *q,char *p) { int root=0; int len=strlen(p); for(int i=0;i<len;i++) { int c=p[i]-'a'; if(tree[root][c]==0) { tree[root][c]=++Node; memset(tree[Node],0,sizeof(tree[Node])); } root=tree[root][c]; } strcpy(ans[root],q); } char* find(char *p) { int root=0; int len=strlen(p); for(int i=0;i<len;i++) { int c=p[i]-'a'; if(tree[root][c]==0) return "AC"; root=tree[root][c]; } return ans[root]; } char ch[N/10]; int main(void) { char p[15],q[15]; scanf("%s",ch); init(); while(scanf("%s",p),strcmp(p,"END")!=0) { scanf("%s",q); insert(p,q); } scanf("%s",ch); getchar(); while(gets(ch)) { if(strcmp(ch,"END")==0) break; char s[15]; int len=strlen(ch); for(int i=0;i<len;) { int j=0; while(i<len&&ch[i]>='a'&&ch[i]<='z') { s[j]=ch[i]; j++; i++; } s[j]='/0'; if(j==0) { printf("%c",ch[i]); i++; continue; } char ss[15]; strcpy(ss,find(s)); if(strlen(ss)==0||strcmp(ss,"AC")==0) printf("%s",s); else printf("%s",ss); } printf("/n"); } }
相关文章推荐
- hdu 1075 字典树
- hdu 1075 字典树
- hdu1075 字典树
- hdu 1075 字典树
- HDU 1075 What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About(字典树)
- HDU 1075字典树(水题)
- hdu 1075 字典树
- HDU 1075 What Are You Talking About (STL, 字典树)
- HDU 1075 字典树
- HDU 1075 What Are You Talking About(字典树)
- HDU - 1075 - What Are You Talking About(字典树)
- Hdu 1075 - What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About (map 或者 字典树)
- HDU 1075 字典树
- HDU 1075 What Are You Talking About (字典树)
- HDU 1075 字典树 树搜索 逆路径输出单词
- hdu 1075 字典树
- hdu 1075 What Are You Talking About(HashMap水过,可用字典树)
- HDU 1075 翻译 (字典树||map)