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
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START difh, i'm fiwo riwosf.
i fiiwj fnnvk! END
Sample Output
hello, i'm from mars.
i like earth!
字典树:先以给的火星文单词建树,并把对应的英文记录在树的末尾。查找时应整个单词的查找。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #include<cstring> #include<cstdio> #include<algorithm> #include<cctype> using namespace std; struct f { int next[30]; int v; char englishi[15]; void ff() { memset (next,-1, sizeof (next)); v=0; englishi[0]= '\0' ; } };f s [1000000]; int cut=0; void charu( char *s1, char *s2) { int i,k=0,su; for (i=0;s2[i]!= '\0' ;i++) { su=s2[i]- 'a' ; if (s[k].next[su]==-1) { cut++; s[k].next[su]=cut; s[cut].ff(); } k=s[k].next[su]; } s[k].v=1; strcpy (s[k].englishi,s1); return ; } int find( char *s1) { int i,k=0,su; for (i=0;i< strlen (s1);i++) { su=s1[i]- 'a' ; if (s[k].next[su]==-1) break ; k=s[k].next[su]; } if (s[k].v&&s[k].englishi[0]!= '\0' &&i== strlen (s1)) { printf ( "%s" ,s[k].englishi); return 0; } return 1; } int main() { char str1[3005],str2[3005]; int z,i; s[cut].ff(); gets (str1); while (~ scanf ( "%s" ,&str1)) { if ( strcmp ( "END" ,str1)==0) break ; scanf ( "%s" ,&str2); charu(str1,str2); } getchar (); gets (str1); while (1) { gets (str1); if (str1[0]== 'E' &&str1[1]== 'N' &&str1[2]== 'D' &&str1[3]== '\0' ) break ; z=0; for (i=0;str1[i]!= '\0' ;i++) { if ( islower (str1[i])) { str2[z]=str1[i]; z++; } else { str2[z]= '\0' ; if (find(str2)) printf ( "%s" ,str2); printf ( "%c" ,str1[i]); z=0; } } if (z!=0) { str2[z]= '\0' ; if (find(str2)) printf ( "%s" ,str2); z=0; } printf ( "\n" ); } return 0; } |
标签:
字典树
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 不到万不得已,千万不要去外包
· C# WebAPI 插件热插拔(持续更新中)
· 会议真的有必要吗?我们产品开发9年了,但从来没开过会
· 【译】我们最喜欢的2024年的 Visual Studio 新功能
· 如何打造一个高并发系统?