题目链接:http://poj.org/problem?id=2503
题意:
给出多行字符串,每行两个, 表示右边映射到左边,然后给出多行字符串,查找是否存在映射。
思路:直接拿map水了一发,题目应该是考察字符串的哈希,感觉还可以字典树来做。
不过这道题输入略显费劲.....
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=100010;
string s;
int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
#endif
map<string,string>mymap;
while(getline(cin,s)){
if(s=="") continue;
if(s.find(' ')!=string::npos){
int cur=s.find(' ');
int len=s.length();
mymap[s.substr(cur+1,len)]=s.substr(0,cur);
}
else{
if(mymap.count(s))
cout<<mymap[s]<<endl;
else
cout<<"eh"<<endl;
}
}
return 0;
}