您的位置:首页 > 其它

poj 2503_Babelfish_map

2016-12-15 20:53 302 查看

题目大意

在一堆字符串中找到匹配的

思路

这题本事hash例题,但考虑到C++字符串的恶意,于是就用了第一次的map

输入然后存入map,判断一下就可以了

#include <stdio.h>
#include <map>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int main()
{
char st[300],st1[300],st2[300];
map<string, string> f;
while (gets(st))
{
if (strlen(st)==0)
break;
sscanf(st,"%s %s",st1,st2);
f[st2]=st1;
}
string s;
string ans;
while (cin>>s)
{
ans=f[s];
if (ans.length()==0)
{
printf("he\n");
}
else printf("%s\n",ans.c_str());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: