您的位置:首页 > 其它

POJ 2503 Babelfish STL-map容器

2017-01-19 11:23 477 查看
传送门:POJ 2503 Babelfish

分析:

利用map容器的键值属性对,通过键高效查找值。

代码如下:

#include <iostream>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
int main()
{
int i;
char str[25],a[12],b[12];
map<string,string> m;
while(gets(str) && str[0]) {
sscanf(str,"%s%s",a,b);
m[b] = a;
}
while(scanf("%s",str) != EOF) {
if(m[str].size()) // 如果找到了m[str]
cout << m[str] << endl;
else
cout << "eh" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  poj map