hdu-1075-What Are You Talking About-(字典树)
2012-08-15 20:55
471 查看
可以在字典树里面标记各种变量。
#include<iostream> #include<cstring> #include<cstdio> using namespace std; struct list { int leap; char str[100]; struct list *next[26]; }; struct list *tree; struct list *code() { int i; struct list *p; p=new list(); p->leap=0; for(i=0;i<26;i++) { p->next[i]=NULL; } return p; } void in(struct list *q,char *str1,char *str2) { int n,i,t; struct list *p; p=q; n=strlen(str2); for(i=0;i<n;i++) { t=str2[i]-'a'; if(p->next[t]==NULL) p->next[t]=code(); p=p->next[t]; } p->leap=1; strcpy(p->str,str1); } void search(struct list *q,char *str) { int n,i,t; n=strlen(str); struct list *p; p=q; for(i=0;i<n;i++) { t=str[i]-'a'; if(p->next[t]==NULL)break; p=p->next[t]; } if(p->leap==1&&i==n) printf("%s",p->str); else printf("%s",str); } int main() { int i,j,n; char str1[100]; char str2[100]; char str[10000]; tree=code(); while(gets(str1)&&strcmp(str1,"START")!=0); while(scanf("%s",str1)&&strcmp(str1,"END")!=0) { scanf("%s",str2); in(tree,str1,str2); } while(gets(str)&&strcmp(str,"START")!=0); while(gets(str)&&strcmp(str,"END")!=0) { n=strlen(str); j=0; for(i=0;i<n;i++) { if(!(str[i]>='a'&&str[i]<='z')) { str1[j]='\0'; search(tree,str1); printf("%c",str[i]); j=0;continue; } str1[j]=str[i]; j++; } if(j!=0) { str1[j]='\0'; search(tree,str1); } printf("\n"); } return 0; }
相关文章推荐
- HDU 1075 What Are You Talking About 经典字典树
- hdu 1075 What Are You Talking About(字典树)
- HDU 1075.What Are You Talking About【Map水题(字典树)】【5月25】
- hdu 1075 What Are You Talking About (字典树)
- HDU-1075 What Are You Talking About 字典树
- hdu 1075 What Are You Talking About(HashMap水过,可用字典树)
- 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(字典树)
- HDU 1075 What Are You Talking About (STL, 字典树)
- 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 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(字典树)
- hdu 1075 What Are You Talking About 字典树
- hdu 1075 What Are You Talking About 字典树 trie