这是一道图论模板题,用分治的策略即可轻松AC!
#include<bits/stdc++.h> using namespace std; string st1,st2,s1,s2; void build(string st1,string st2) { int len = st1.length(); if (len == 0) return ; cout<<st2[len-1]; int p = st1.find(st2[len-1]); s1 = st1.substr(0,p); s2 = st2.substr(0,p); build(s1,s2); s1 = st1.substr(p+1,len); s2 = st2.substr(p,len-1); build(s1,s2); } int main() { cin>>st1>>st2; int len = st1.length(); cout<<st2[len-1]; int p = st1.find(st2[len-1]); s1 = st1.substr(0,p) , s2 = st2.substr(0,p); build(s1,s2); s1 = st1.substr(p+1,len); s2 = st2.substr(p,len-1); build(s1,s2); return 0; }