POJ 2503 Babelfish (dictionary tree)

Source: Internet
Author: User

Babelfish
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 35009 Accepted: 14979

Description

You are just moved from Waterloo to a big city. The people speak an incomprehensible dialect of a foreign language. Fortunately, you had a dictionary to help you understand them.

Input

Input consists of 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words . Each dictionary entry are a line containing an 中文版 word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language and one word on each line. Each word in the input is a sequence of lowercase letters.

Output

Output is the message translated to 中文版, one word per line. Foreign words not in the dictionary should is translated as "eh".

Sample Input

Dog Ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Sample Output

Catehloops

Pure Dictionary tree water problem. Knowledge Learned:the ①SSCANF function, the sibling of the scanf function, reads the string into the specified variable in the specified format. The ②node node is empty, can be used without null, but is 0 more concise and secure.
/*trie (dictionary tree) */#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> Using namespace std;typedef __int64 ll;typedef struct Node{char word[15];struct Node *ch[27];//did not think that the initial value of ch[] could be 0, At first I exited with a null exception}node;node *t;int index;void Add (char S[],char wd[]) {node *u;u=t;int Len=strlen (s), I;for (i=0;i<len;i + +) {if (u->ch[s[i]-' a ']==0) {node *t= (node*) malloc (sizeof (node)); for (int j=0;j<27;j++) t->ch[j]=0;u->ch [s[i]-' a ']=t;} U=u->ch[s[i]-' a '];} strcpy (U->WORD,WD);} void Ask (char s[]) {node* u=t;int I,len=strlen (s); for (i=0;i<len;i++) {if (u==0) {printf ("eh\n"); return;} Else u=u->ch[s[i]-' a '];} printf ("%s\n", U->word);} int main () {int I,k,j;char s1[20],s2[20],str[50]; t= (node*) malloc (sizeof (node)), for (i=0;i<27;i++) t->ch[i]=0;while (gets (str)) {if (str[0]== ') break;sscanf ( STR, "%s%s", s1,s2);//requires SSCANF to handle add (S2,S1);} while (scanf ("%s", S1)!=eof) {ask (S1);} return 0;}


POJ 2503 Babelfish (dictionary tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.