poj 2503 Babelfish
来源:互联网 发布:软件测试怎么自学 编辑:程序博客网 时间:2024/06/05 16:22
//用一个映射器就很容易解决问题了! #include "iostream"#include "string"#include "map"using namespace std;map<string, string> m;int main(){ string input, first, second; int pos, i, len; while (getline(cin, input))//将一个字符串分隔为两个字符串,分别装入map容器中 { first.clear(); second.clear(); pos = 0; if (input.length() == 0) break; len = input.length(); for (i = 0; i < len; i++) { if (input[i] != ' ') pos++; else break; } for (i = 0; i < pos; i++) first.push_back(input[i]); for (i = pos+1; i < len; i++) second.push_back(input[i]); m[second] = first; } string str; while (cin >> str) { if (m[str].length() != 0)//判断是否有元素与之对应 cout << m[str] << endl; else cout << "eh" << endl; }}