-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Don_t_Try_to_Count.java
53 lines (53 loc) · 1.69 KB
/
A_Don_t_Try_to_Count.java
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
import java.util.*;
public class A_Don_t_Try_to_Count{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-->0) {
int n, m;
n = scanner.nextInt();
m = scanner.nextInt();
String x, s;
x = scanner.next();
s = scanner.next();
int count = 0;
int k = x.length();
if (n == m) {
if (x.indexOf(s) != -1)
System.out.println(0);
else {
x = x + x;
if (x.indexOf(s) == -1)
System.out.println(-1);
else
System.out.println(1);
}
} else if (n > m) {
if (x.indexOf(s) != -1)
System.out.println(0);
else {
x = x + x;
if (x.indexOf(s) == -1)
System.out.println(-1);
else
System.out.println(1);
}
} else {
while (s.length() > x.length()) {
x = x + x;
count++;
}
if (x.indexOf(s) != -1)
System.out.println(count);
else {
x = x + x;
count++;
if (x.indexOf(s) == -1)
System.out.println(-1);
else
System.out.println(count);
}
}
}
}
}