基本思想:
无;
关键点:
无;
#include<iostream> #include<string> #include<vector> #include<map> using namespace std; int main() { int n; string s; map<string, string>spll2tell; map<string, string>tell2spell; while (getline(cin,s)){ if (s == "@END@") break; int index=-1; for (int i = 0; i < s.size(); i++) { if (s[i] == ‘]‘) { index = i; break; } } string spll = s.substr(0, index+1); string tell = s.substr(index + 2, s.size() - (index + 2)); //cout << spll << " " << tell << endl; spll2tell[spll] = tell; spll = s.substr(1, index - 1); tell2spell[tell] = spll; } cin >> n; getchar(); for (int i = 0; i < n; i++) { getline(cin, s); if (spll2tell.find(s) != spll2tell.end()) { cout << spll2tell[s] << endl; } else if (tell2spell.find(s) != tell2spell.end()) { cout << tell2spell[s] << endl; } else { cout << "what?" << endl; } } return 0; }
原文:https://www.cnblogs.com/songlinxuan/p/12422760.html