POJ2503 babelfish "Map"

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=2503


Main topic:

Give you a dictionary. Every behavior in the dictionary is one English word and one other country word. So that we can use the dictionary to put the English words

Translated into other country words, you can also translate other country words into English words. Now give you a few foreign words, Q: In the dictionary

Whether there is a translation of this word. If so, output the translation, otherwise, output "eh".


Ideas:

This problem can actually be done using a map or a dictionary tree in the STL. Map's approach is to create two maps, one for storing translations, one for

To determine if a translation exists. Note that input can be entered in a row first to determine whether it is "\ n". Then use sscanf to add English words and

Other countries the word is split into two string s,t. Then save them with a map. The output is then judged according to the input words.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < String> #include <map>using namespace Std;char s[11],t[11],word[11],str[22];int main () {    map<string, String> H;    Map<string,bool> HH;    while (gets (str))    {        if (strlen (str) = = 0) break            ;        SSCANF (str, "%s%s", s,t);        H[t] = s;        Hh[t] = true;    }    while (CIN >> Word)    {        if (Hh[word])            cout << H[word] << Endl;        else            cout << "eh" << Endl;    }    return 0;}



POJ2503 babelfish "Map"

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.