原题链接
题解
这个题目貌似是个模拟题,直接模拟就是了
代码如下
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
set<string> s;
int main(){
int T; cin >> T;
for(int k = 1; k <= T; ++ k){
int n; cin >> n;
string s1, s2, s12;
string t = "";
cin >> s1 >> s2 >> s12;
int res = 0; bool flag = false;
while(!s.count(t)){
s.insert(t); t = "";
for(int i = 0; i < n; ++ i) t += s2[i], t += s1[i];
res ++;
if(t == s12) {flag = true; break;}
s1 = t.substr(0, n);
s2 = t.substr(n, n);//题目中是说最高的C个,不是高的C个的顶部开始,不需要反转
}
cout << k << ' ';
if(!flag) cout << -1 << '
';
else cout << res << '
';
s.clear();
}
return 0;
}