2023-11-13 12:56:19
发布于:广东
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int x, y;
cin >> x >> y;
string a, b;
cin >> a >> b;
int la = a.length();
for(int i = 1; i <= 5; i++){
a += a;
}int xx = 0;
int lena = a.length(), lenb = b.length();
bool flag = 0;
int i, j;
for(i = 0; i < lena; i++){
if(a[i] == b[0]){
bool flag1 = 1;
for(j = 0; j < lenb; j++){
if(a[i + j] != b[j]){
flag1 = 0;
break;
}
}if(flag1){
flag = 1;
xx = i;
break;
}
}
}if(flag){
int ct = 0;
for(; la < xx + lenb; la *= 2){
ct++;
}cout << ct << "\n";
}
else cout << -1 << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个