扫扫尾,今天把初级的数据结构都完成了它,进军中级图论,算法导论看得很爽!
这题没啥好说的,map搞定
#include <iostream>
#include <string> #include <map> #include <set> using namespace std; int main() { string s, a, b; map<string, bool> apperance; map<string, string>dic; while (getline(cin, s) && s != "") { int pos = s.find(" "); a.assign(s, 0, pos); b.assign(s, pos+1, sizeof(s)-1); apperance.insert(make_pair(b, true)); dic.insert(make_pair(b, a)); } while (cin >> s) { if (apperance[s]) { cout << dic[s] << endl; } else { cout << "eh" << endl; } } } |