-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdonttry.cpp
More file actions
92 lines (89 loc) · 1.99 KB
/
Copy pathdonttry.cpp
File metadata and controls
92 lines (89 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//#include<bits/stdc++.h>
//using namespace std;
//int main()
//{
// int t;
// cin>>t;
// while(t--)
// {
// int n,m;
// cin>>n>>m;
// string s1,s2;
// cin>>s1>>s2;
// int cnt=0;
// int sz1=s1.size();
// int sz2=s2.size();
// bool flag=false ;
//
// if(sz1>sz2)
// {
// cout<<0<<endl;
// }
// else
// {
// while(sz1<sz2)
// {
//
// s1=s1+s1;
// size_t found = s2.find(s1);
// if (found != string::npos)
// {
// cnt++;
// flag=true;
// break;
// }
// else
// {
// cnt++;
// }
// }
// }
//
// if(flag)
// {
// cout<<" ans is : "<<cnt<<endl;
// }
// else
// {
// cout<<" ans is : "<<-1<<endl;
// }
// }
//}
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s1, s2;
cin >> s1 >> s2;
int cnt = 0;
int sz1 = s1.size();
int sz2 = s2.size();
bool flag = false;
if (sz1 > sz2) {
cout << 0 << endl;
} else {
while (sz1 < sz2) {
s1 = s1 + s1;
sz1 = s1.size(); // Update sz1 after concatenation
size_t found = s2.find(s1);
if (found != string::npos) {
cnt++;
flag = true;
break;
} else {
cnt++;
}
}
}
if (flag) {
cout << "ans is : " << cnt << endl;
} else {
cout << "ans is : " << -1 << endl;
}
}
return 0;
}