题目链接:
传送门
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
string s1,s2,str,stds;
int main() {
int t, len, ans, i, ca = 1, flag = 1;
cin >> t;
//t个实例
while (t--) {
cin >> len;
cin >> s1 >> s2 >> str;
stds = str;
ans = 0;
flag = 1;
//800存粹取巧还是写一下跳出条件好[哭笑]
while (ans<800) {
int i = 0;
while (i < len) {
str[i*2] = s2[i];
str[i*2+1] = s1[i];
i++;
}
ans++;
if (str==stds) {
cout << ca++ << " " << ans << endl;
flag = 0;
break;
}
s1 = str.substr(0, len);
s2 = str.substr(len);
}
if (flag) {
cout << ca << " " << -1 << endl;
ca++;
}
}
return 0;
}
这道题的大致思路是先把两个字符串各个字符分隔着插入,然后重复操作,直到拼接成想要的字符串为止。