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 中文版. Can you help him?
Input
The problem has only one test case, the test case consists of the parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should is ignored, then some lines fo Llow, each line contains and strings, the first one is a word in 中文版, the second one is the corresponding word in Mart Ian ' s language. A line with a single string "End" indicates the end of the directory part, and this string should is ignored. The book part starts with a single line contains a string "START", this string should is ignored, then an article written In Martian ' s language. You should translate the article into 中文版 with the dictionary. If you find the word in the dictionary should translate it and write the new Word to your translation if you can ' t Find the word in the "dictionary" is not a 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 is in the lowercase, and each word would contain at most of the characters, and each line would contain at most 3 Characters.
Output
In this problem, you has the to output the translation of the history book.
Sample Input
Startfrom Fiwo Hello difh mars riwosfearth fnnvklike fiiwjend START difh, i ' m fiwo riwosf.i fiiwj fnnvk! END
Sample Output
Hello, I ' M from Mars. I like earth! Dictionary tree: First make a contribution to the Martian words, and record the corresponding English at the end of the tree. The search should look for the entire word.
#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]= ' + '; }};f s [1000000];int cut=0;void Charu (char *s1,char *s2) {int i,k=0,su; for (i=0;s2[i]!= '; 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]!= ' &&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]== ') break; z=0; for (i=0;str1[i]!= '; i++) {if (Islower (Str1[i])) {str2[z]=str1[i]; z++; } else {str2[z]= ' + '; if (find (STR2)) printf ("%s", str2); printf ("%c", Str1[i]); z=0; }} if (z!=0) {str2[z]= ' + '; if (find (STR2)) printf ("%s", str2); z=0; } printf ("\ n"); } return 0;}
HDOJ-1075 what is talking about the dictionary tree