將字典用Map存下後再將輸入拿去查詢即可得解。
C++(0.310)
/*******************************************************/
/* UVa 10282 Babelfish */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2016/04/14 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <map>
using namespace std;
int main(){
string input;
map<string, string> dictionary;
while( getline(cin, input) && input != "" ){
stringstream ss(input);
string key, value;
ss >> value >> key;
dictionary[key] = value;
}
while( getline(cin, input) ){
if( dictionary.find(input) == dictionary.end() ){
printf("eh\n");
}
else {
printf("%s\n", dictionary[input].c_str());
}
}
return 0;
}