POJ 2503 -- Babelfish
Babelfish
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 47018 | Accepted: 19709 |
Description
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English 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, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Sample Input
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
Sample Output
cat
eh
loops
Hint
Huge input and output,scanf and printf are recommended.
Source
题意:
输入一个字典,字典格式为“英语à外语”的一一映射关系
然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh”
解题思路:
输入时顺便用STL的map建立 外语 =》英语 的映射,那么输出时用map.find(外语)查找,若有出现过,再输出映射,否则输出“eh”。
这里需要注意,想要直接cout<<string ,需要引入<string>头文件,<cstring>也不行!!不然POJ编译器会Compile Error
标红告诫自己
1 #include<map> 2 #include<cstring> 3 #include<iostream> 4 #include<cstdio> 5 #include<string> 6 using namespace std; 7 map<string,string> dir; 8 int main() 9 { 10 char a[12],b[12]; 11 char temp; 12 temp = getchar(); 13 while(temp != '\n') 14 { 15 ///输入英文单词 16 int i=0; 17 while(temp != ' ') 18 { 19 a[i++] = temp; 20 temp = getchar(); 21 } 22 a[i] = '\0'; 23 ///输入外语 24 cin>>b; 25 getchar();//吃掉每行的换行符 26 27 dir[b] = a; 28 29 temp = getchar(); 30 } 31 32 while(cin>>b && b[0]!='\n') 33 { 34 map<string,string>::iterator iter; 35 iter = dir.find(b); 36 if(iter == dir.end())//没有找到 37 cout<<"eh"<<endl; 38 else 39 cout<<iter->second<<endl; 40 } 41 42 return 0; 43 }