POJ2503 Babelfish

题目链接

分析:

应当用字典树,但stl的map做很简单.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>

using namespace std;

const int maxn = 20;

map<string, string> m;

int main() {
    char s[maxn], s1[maxn], s2[maxn];

    while(gets(s), s[0] != 0) {
      sscanf(s, "%s%s", s1, s2);
      m[s2] = s1;
    }

    while(gets(s) && s[0] != 0) {//这里s[0] != 0也要加上
      if(m.count(s) == 0) printf("eh\n");
       else cout << m[s] << endl;
    }
    
    return 0;
}

 

posted on 2013-07-31 23:49  Still_Raining  阅读(128)  评论(0编辑  收藏  举报