HDU 1075 字典树 字符串匹配
来源:互联网 发布:淘宝佣金结算时间 编辑:程序博客网 时间:2024/05/29 14:03
题目:
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 11683 Accepted Submission(s): 3737
Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
Output
In this problem, you have to output the translation of the history book.
Sample Input
STARTfrom fiwohello difhmars riwosfearth fnnvklike fiiwjENDSTARTdifh, i'm fiwo riwosf.i fiiwj fnnvk!END
Sample Output
hello, i'm from mars.i like earth!HintHuge input, scanf is recommended.
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<ctype.h>struct dictree{dictree *child[26];char aim[15];int flag;}*root;char ans[15];int flag;void insert(char*source,char*temp){int i,j;dictree *newnode,*current;current=root;for(i=0;i<strlen(source);i++){if(current->child[source[i]-'a']!=0)current=current->child[source[i]-'a'];else{newnode=new dictree;newnode->flag=0;for(j=0;j<26;j++)newnode->child[j]=0;current->child[source[i]-'a']=newnode;current=newnode;}}current->flag=1;strcpy(current->aim,temp);}void find(char*source){dictree *current;int i;current=root;for(i=0;i<strlen(source);i++){if(current->child[source[i]-'a']!=0)current=current->child[source[i]-'a'];else{flag=1;return;}}if(current->flag==0){flag=1;return;}strcpy(ans,current->aim);}int main(){int i,j;char str1[15],str2[15],str[3300],temp[15];scanf("%s",str1);root=new dictree;for(i=0;i<26;i++)root->child[i]=0;root->flag=0;while(scanf("%s",str1)&&strcmp(str1,"END")!=0){scanf("%s",str2);insert(str2,str1);}scanf("%s",str);getchar();while(gets(str)&&strcmp(str,"END")!=0){j=0;for(i=0;i<strlen(str);i++){if(islower(str[i]))temp[j++]=str[i];else{if(j){temp[j]=0;flag=0;find(temp);if(flag)printf("%s",temp);elseprintf("%s",ans);}if(str[i])printf("%c",str[i]);j=0;}}printf("\n");}return 0;}
0 0
- HDU 1075 字典树 字符串匹配
- 字符串、字典匹配算法
- [字典树]hdu 1075
- hdu 1075 字典树
- 字典树 hdu 1075
- hdu 1075 字典树
- HDU 1075 字典树
- hdu 1075 字典树
- hdu 1075 字典树
- 字典树 hdu 1075
- hdu 1075 字典树
- hdu 1075 字典树
- HDU 1075 字典树
- 字典树 hdu 1075
- hdu 1075 字典树
- HDU 1075 字典树
- hdu 1075 字典树
- Google字符串模糊匹配算法,字典树模糊查询
- HDU 1027 组合数学
- 开始使用Ubuntu作为工作环境
- HDU 1086 计算几何 判断线段相交
- Android之退出整个应用方法之一
- Android开源项目2
- HDU 1075 字典树 字符串匹配
- ZZ焦涛:刘未鹏博客阅读总结
- IOS传值---属性传值、代理委托传值(delegate)传值、单例传值、block传值
- KMP算法
- 【递推】【DP】-HDU-1207-汉诺塔②
- HDU 1434 链表 幸福列车
- 25-Linux-服务-FTP基础
- Win32汇编扩展教程
- HDU 1023 高精度 卡特兰数