#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
#define INF 0x3f3f3f
int gcd(int a, int b) {return b==0 ? a:gcd(b,a%b);}
int main()
{
int t;
cin >> t;
for(int tt = 1; tt <= t; tt++)
{
int n;
cin >> n;
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
string s = "";
map<string,int>q;
int cnt = 0;
int flag = 0;
while(1)
{
s.clear();
for(int i = 0; i < n; i++)
{
s += s2[i]; s += s1[i];
}
cnt++;
if(q[s]==1) break;
q[s] = 1;
if(s==s3){
flag = 1;
break;
}
s1 = s.substr(0,n);
s2 = s.substr(n);
}
printf("%d ", tt);
if(!flag) printf("-1\n");
else printf("%d\n", cnt);
}
return 0;
}
[kuangbin带你飞]专题一 简单搜索- G - Shuffle‘m Up
最新推荐文章于 2020-07-26 20:59:18 发布