-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhometask.java
More file actions
36 lines (35 loc) · 1.03 KB
/
hometask.java
File metadata and controls
36 lines (35 loc) · 1.03 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
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
public class hometask {
static int mod = (int) 1e9 + 7;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
StringBuilder sb=new StringBuilder(sc.next());
int[] arr=new int[26];
for(int i=0;i<sb.length();i++)arr[sb.charAt(i)-'a']++;
int k=sc.nextInt(),count=0;
while(k-->0){
String z=sc.next();
int a=0,b=0;
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)==z.charAt(0)){
a++;continue;
}
else if(sb.charAt(i)==z.charAt(1)){
b++;continue;
}
count+=Math.min(a,b);
a=0;b=0;
}
count+=Math.min(a,b);
a=0;b=0;
}
System.out.println(count);
}
}