hdu 1075 字典树
2012-08-20 03:14
246 查看
int 定义为char,re了2个小时,人才啊。。。。。。。。。。。。
注意点,abc 对应efg,输入efg应该输出abc,输入ef呢?
注意输入前缀无输出的情况
注意点,abc 对应efg,输入efg应该输出abc,输入ef呢?
注意输入前缀无输出的情况
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<cstring> #include"ctype.h" struct Dictree { int no; struct Dictree *next[26]; }*root; char str[500005][15],s[3005],p[2005]; void create_tree(); void insert(char *,int ); int find(char *); int main() { int i=0,j=0,k=0,temp,len; create_tree(); scanf("%s",s); while(scanf("%s",str[i]),strcmp(str[i],"END")!=0) { scanf("%s",p); insert(p,i++); } scanf("%s",s),getchar(); while(gets(s)) { if(strcmp(s,"END")==0) break; len=strlen(s); k=0; for(j=0;j<len;j++) { if(islower(s[j])) p[k++]=s[j]; else { if(k) { p[k]=0; temp=find(p); if(temp==-1) printf("%s",p); else printf("%s",str[temp]); } if(s[j]) printf("%c",s[j]); k=0; } } memset(s,0,sizeof(s)); putchar('\n'); } return 0; } void insert(char *s,int k) { int i,j; struct Dictree *p,*t; p=root; for(i=0;s[i];i++) { if(p->next[s[i]-'a']==NULL) { t=(struct Dictree*)malloc(sizeof(struct Dictree)); t->no=-1; for(j=0;j<26;j++) t->next[j]=NULL; p->next[s[i]-'a']=t; } p=p->next[s[i]-'a']; } p->no=k; } int find(char *s) { int i; struct Dictree *p=root; for(i=0;s[i];i++) { if(p->next[s[i]-'a']==NULL) return -1; else p=p->next[s[i]-'a']; } return p->no; } void create_tree() { int i; root=(struct Dictree*)malloc(sizeof(struct Dictree)); root->no=-1; for(i=0;i<26;i++) root->next[i]=NULL; }
相关文章推荐
- HDU 1075 What Are You Talking About (map 或者 字典树)
- HDU 1075字典树(水题)
- 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 字典树
- HDU 1075 字典树
- HDU 1075 What Are You Talking About (字典树)
- HDU 1075 字典树 树搜索 逆路径输出单词
- hdu 1075 What Are You Talking About(HashMap水过,可用字典树)
- HDU 1075 翻译 (字典树||map)
- 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【字典树】or【字符串map】
- hdu 1075 字典树
- hdu 1075 What Are You Talking About(字典树)