POJ 2503 -- Babelfish
阿新 • • 發佈:2018-02-12
lis pil cst miss ima align 存在 temp cep
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
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
Waterloo local 2001.09.22
題意:
輸入一個字典,字典格式為“英語à外語”的一一映射關系
然後輸入若幹個外語單詞,輸出他們的 英語翻譯單詞,如果字典中不存在這個單詞,則輸出“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 }
POJ 2503 -- Babelfish