-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
34 lines (34 loc) · 750 Bytes
/
Copy pathMain.java
File metadata and controls
34 lines (34 loc) · 750 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
30
31
32
33
34
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;
}
for (int i = 0 ; i<26 ; i++)
B[i] = ~B[i];
//Searching
int counter = 0;
int D = ~0;
for (int i = 0; i<n ; i++)
{
D = (D << 1 | B[T.charAt(i) - 'a']);
if((D & 1<<(m-1)) == 0)
counter++;
}
System.out.println(counter);
sc.close();
}
}