POJ 2503 Babelfish (dictionary tree or STL)

Source: Internet
Author: User
Tags cmath

Babelfish
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 35828 Accepted: 15320

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

Hint

Huge input and output,scanf and printf are recommended.

Source

Waterloo Local 2001.09.22




STL same second kill I suspect the dictionary tree has a chicken feather, test sample too little!


STL:

#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include < string.h> #include <cctype> #include <string> #include <cmath> #include <vector> #include <stack> #include <queue> #include <map> #include <set>using namespace Std;int main () {    String str;map<string,string >cnt;    while (Getline (CIN,STR) &&str[0]!=0)    {        int loc=str.find ("");        Cnt[str.substr (Loc+1,str.size ()-loc-1)]=str.substr (0,loc);    }    while (CIN>>STR)    {        if (Cnt.count (str))            cout<<cnt[str]<<endl;        else            cout<< "eh" <<endl;    }    return 0;}

Dictionary tree:

#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include < string.h> #include <cctype> #include <string> #include <cmath> #include <vector> #include <stack> #include <queue> #include <map> #include <set>using namespace std;typedef struct    nodetype{struct NodeType * child[26];    char word [11];    int Isword;        NodeType () {memset (child,null,sizeof (child));    Isword=0;    }} node;void Insertword (Node *node,char *wo,char *wt) {int id;        while (*WT) {id=*wt-' a ';        if (Node->child[id]==null) node->child[id]=new node ();        node=node->child[id];    wt++;    } node->isword=1; strcpy (NODE-&GT;WORD,WO);}    char * Searchword (Node * Node,char *wd) {char *noword= "eh";    int id;        while (*WD) {id=*wd-' a ';        if (node->child[id]==null) return noword;        node=node->child[id];    wd++; } if (Node->isWord) return node->word; else return Noword;}    int main () {char cnt[40],dict[40],buf[40];    Node * node=new node;        while (gets (BUF) &&buf[0]!=0) {int i=0;        for (; buf[i]!=32; i++) cnt[i]=buf[i];        cnt[i]=0;        Int J;        for (++i,j=0; buf[i]; i++,j++) dict[j]=buf[i];        dict[j]=0;    Insertword (node,cnt,dict);        } while (scanf ("%s", CNT)!=eof) {Char *word = Searchword (node,cnt);    printf ("%s\n", word); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2503 Babelfish (dictionary tree or STL)

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.