-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongestCommenPattern.java
More file actions
53 lines (52 loc) · 1.37 KB
/
LongestCommenPattern.java
File metadata and controls
53 lines (52 loc) · 1.37 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
52
53
package codechef;
import java.io.*;
public class LongestCommenPattern {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
short t = Short.parseShort(br.readLine());
while(t>0){
String s1 = br.readLine();
String s2 = br.readLine();
int a[] = new int[26];
for(int i = 0 ; i<26 ; i++){
a[i] = 0;
}
int A[] = new int[26];
for(int i = 0 ; i<26 ; i++){
A[i] = 0;
}
int d[] = new int[10];
for(int i = 0 ; i<10 ; i++){
d[i] = 0;
}
for(int i = 0 ; i<s1.length() ; i++){
if(s1.charAt(i)>='0' && s1.charAt(i)<='9'){
d[s1.charAt(i)-'0']++;
}
else if(s1.charAt(i)>='a' && s1.charAt(i)<='z'){
a[s1.charAt(i)-'a']++;
}
else if(s1.charAt(i)>='A' && s1.charAt(i)<='Z'){
A[s1.charAt(i)-'A']++;
}
}
int count = 0;
for(int i = 0 ; i<s2.length() ; i++){
if(s2.charAt(i)>='0' && s2.charAt(i)<='9' && d[s2.charAt(i)-'0'] > 0){
d[s2.charAt(i)-'0']--;
count++;
}
else if(s2.charAt(i)>='a' && s2.charAt(i)<='z' && a[s2.charAt(i)-'a'] > 0){
a[s2.charAt(i)-'a']--;
count++;
}
else if(s2.charAt(i)>='A' && s2.charAt(i)<='Z' && A[s2.charAt(i)-'A'] > 0){
A[s2.charAt(i)-'A']--;
count++;
}
}
System.out.println(count);
t--;
}
}
}