POJ_2503 Babelfish
問題
辞書データとクエリが与えられるので、翻訳した結果を表示せよ。
辞書に載っていない場合"eh"と表示せよ
解法
辞書データはmapで管理した。
入力の処理に少し工夫が必要。
#include <cstdio> #include <cstring> #include <string> #include <map> #include <algorithm> using namespace std; typedef map<string, string> DIC; int main(){ char a[100], b[100]; char next; DIC dic; scanf("%c", &next); while(true){ a[0] = next; scanf("%s %s", &a[1], b); scanf("%c", &next); scanf("%c", &next); dic.insert(DIC::value_type(string(b), string(a))); if(next == '\n') break; } while(scanf("%s", a) != EOF){ scanf("%c", &next); if(dic.find(string(a)) != dic.end()){ printf("%s\n", dic[string(a)].c_str()); }else{ printf("eh\n"); } } return 0; }