//用一个映射器就很容易解决问题了!
#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;
}
}
poj 2503 Babelfish
最新推荐文章于 2021-03-20 00:18:40 发布