hdu 1075 What Are You Talking About(Trie树)
2012-08-13 20:34
429 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1075
View Code
View Code
#include<iostream> #include<cstring> #include<cstdio> #include<stdlib.h> using namespace std; struct node { int flag; char st[101]; node *next[26]; }; node *build() { int i; node *p; p=new node; p->flag=0; for(i=0;i<26;i++) p->next[i]=NULL; return p; } void insert(node *p,char *s1,char *s2) { int i,len1,t; len1=strlen(s1); for(i=0;i<len1;i++) { t=s1[i]-'a'; if(p->next[t]==NULL) p->next[t]=build(); p=p->next[t]; } p->flag=1; strcpy(p->st,s2); } int search(node *p,char *s) { int t,i,len; len=strlen(s); for(i=0;i<len;i++) { t=s[i]-'a'; if(p->next[t]==NULL) return 0; p=p->next[t]; } if(p->flag==1) { printf("%s",p->st); return 1; } return 0; } int main() { int i,j,len,len2,k; char str1[10001],str2[10005]; node *p; gets(str1); if(strcmp(str1,"START")==0) { p=build(); while(~scanf("%s%*c",str1)) { if(strcmp(str1,"END")==0) break; scanf("%s",str2); insert(p,str2,str1); } } gets(str1); if(strcmp(str1,"START")==0) { while(gets(str1)!=NULL) { if(strcmp(str1,"END")==0) break; len=strlen(str1); j=0; for(i=0;i<len;i++) { if(str1[i]>='a'&&str1[i]<='z') { str2[j]=str1[i]; j++; } else { if(j!=0) { str2[j]='\0'; j=0; if(search(p,str2)==0) printf("%s",str2); printf("%c",str1[i]); } else printf("%c",str1[i]); } } if(j!=0) { str2[j]='\0'; if(search(p,str2)==0) printf("%s",str2); } puts(""); } } return 0; }
相关文章推荐
- HDU 1075——What Are You Talking About(Trie树)
- HDU 1075 What are you talking about(trie树)
- hdu 1075 What Are You Talking About(Trie树)
- hdu 1075 What Are You Talking About (Trie树,水题)
- hdu 1075 What Are You Talking About(Trie树)
- 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 【map + find】
- 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
- HDU 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About(用map进行翻译)
- hdu----(1075)What Are You Talking About(trie之查找)
- HDU 1075-What Are You Talking About(Trie)