(反省点)
int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { vector<string> com; vector<string> del; string v; int nc, nd, nv; cin>>nc; REP(i, nc) { string tmp; cin>>tmp; com.PB(tmp); } cin>>nd; REP(i, nd) { string tmp; cin>>tmp; del.PB(tmp); } cin>>nv; cin>>v; //cout<<com<<del<<v<<endl; vector<char> w; REP(i, nv) { w.PB(v[i]); if(w.SZ>=2) REP(j, nc) { if(w[w.SZ-2]==com[j][0] && w[w.SZ-1]==com[j][1]) { w.pop_back(); w.pop_back(); w.PB(com[j][2]); } if(w[w.SZ-2]==com[j][1] && w[w.SZ-1]==com[j][0]) { w.pop_back(); w.pop_back(); w.PB(com[j][2]); } } if(w.SZ>=2) REP(j, nd) { if(w[w.SZ-1]==del[j][0]) REP(k, w.SZ-1) { if(w[k]==del[j][1]) { w.clear(); } } if(w[w.SZ-1]==del[j][1]) REP(k, w.SZ-1) { if(w[k]==del[j][0]) { w.clear(); } } } } cout<<"Case #"<<t+1<<": "<<w<<endl;; } return 0; }