hdu 1880

水题,记录一下,处理输入挺有意义。

#include #include #include #include using namespace std; map m1; map m2; string s1, s2; map::iterator iter; int main() { while(cin >> s1 && s1[0] != '@') { while(s1[s1.length() - 1] != ']') { s1 += ' '; cin >> s2; s1 += s2; } cin.ignore(); getline(cin, s2); m1.insert(make_pair(s1, s2)); s1.erase(s1.length() - 1, 1); s1.erase(0, 1); m2.insert(make_pair(s2, s1)); } int n; cin >> n; cin.ignore(); while(n--) { getline(cin, s1); if((iter = m1.find(s1)) != m1.end()) { cout << iter->second << endl; continue; } if((iter = m2.find(s1)) != m2.end()) { cout << iter->second << endl; continue; } cout << "what?" << endl; } return 0; } 

你可能感兴趣的:(算法之路)