-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathanti.java
More file actions
51 lines (31 loc) · 1.19 KB
/
anti.java
File metadata and controls
51 lines (31 loc) · 1.19 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Anticman {
public static void anti() throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(reader.readLine());
int i =0;
while( i<num){
String str1= reader.readLine();
String str2 = reader.readLine();
String alpha="abcdefghijklmnopqrstuvwxyz";
int[] list1 = new int[26];
int[] list2 = new int[26];
for (int j=0;j<str1.length();j=j+1){
char a = str1.charAt(j);
char b = str2.charAt(j);
int inda = alpha.indexOf(a);
list1[inda]=list1[inda]+1;
int indb = alpha.indexOf(b);
list2[indb]=list2[indb] + 1;}
for (int e=0;e<26;e=e+1){
int k = Math.min(list1[e],list2[e]);
for (int z=0;z<k;z++){
System.out.print(alpha.charAt(e));}}
i=i+1;
System.out.println();
}
}
public static void main(String[] args) throws Exception{
anti();}
}