-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblocks.java
58 lines (42 loc) · 1.43 KB
/
blocks.java
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
54
55
56
57
58
/**
* Created by supersteve on 12/16/16.
*/
import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class blocks {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader f = new BufferedReader(new FileReader("blocks.in"));
// input file name goes above
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("blocks.out")));
int n = Integer.parseInt(f.readLine());
ArrayList<String> a = new ArrayList<String>();
ArrayList<String> b = new ArrayList<String>();
for(int i = 0; i< n;i++) {
StringTokenizer st = new StringTokenizer(f.readLine());
a.add(st.nextToken());
b.add(st.nextToken());
}
int[] c = new int[26];
for(int i = 0; i<n;i++){
int[] a1 = new int[26];
int[] b1 = new int[26];
String astring = a.get(i);
String bstring = b.get(i);
for(int j = 0; j<astring.length();j++){
a1[(astring.charAt(j)-'a')] +=1;
}
for(int j = 0; j<bstring.length();j++){
b1[(bstring.charAt(j)-'a')] +=1;
}
for(int j = 0; j<26;j++){
c[j]+=Math.max(a1[j],b1[j]);
}
}
for(int i = 0; i<26; i++){
out.println(c[i]);
}
out.close();
}
}