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"