The topic is to practice map because it is possible to find value from key, and value to find key two cases, so two map is required because map can only find value from key. It also tests the processing of strings.
#include <iostream> #include <map> #include <string> #include <cstdio>using namespace std; int main () {map<string,string>maps; map<string,string>maps1; Map<string,string>::iterator F; String A; int n; while (Getline (cin,a)) {if (a== "@[email protected]") break; int end = A.find ('] '); string tmp = A.SUBSTR (1,end-1); String tmp1 = A.substr (End+2,a.length ()-1); MAPS[TMP]=TMP1; maps1[tmp1]=tmp; } cin>>n; GetChar (); for (int i=0;i<n;i++) {getline (cin,a); if (A.find (' [')!=-1) {a = A.substr (1,a.length ()-2); f = Maps.find (a); if (F==maps.end ()) cout<< "What?" <<endl; else cout<<maps[a]<<endl; } else{F = Maps1.find (a); if (F==maps1.end ()) cout<< "What?" <<endl; else COUT≪<maps1[a]<<endl; }} return 0;}
Nine degrees 1029-map-magic Spell Dictionary