-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (28 loc) · 699 Bytes
/
Copy pathMain.java
File metadata and controls
29 lines (28 loc) · 699 Bytes
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String P = sc.next().toLowerCase();
String T = sc.next().toLowerCase();
int m = P.length();
int n = T.length();
int B[] = new int[26];
// preprocessing
int mask = 1;
for (int i = 0; i < m; i++) {
int p = P.charAt(i) - 'a';
B[p] = (B[p] | mask);
mask = mask << 1;
}
// Searching
int D = 0;
int counter = 0;
for (int i = 0; i < n; i++) {
D = (D << 1 | 1) & B[T.charAt(i) - 'a'];
if ((D & 1 << (m - 1)) != 0)
counter++;
}
System.out.println(counter);
sc.close();
}
}