-
Notifications
You must be signed in to change notification settings - Fork 15
/
deduplicatingfiles.java
36 lines (34 loc) · 1.18 KB
/
deduplicatingfiles.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
import java.io.*;
import java.util.*;
public class deduplicatingfiles {
public static void main(String[] args) throws Exception {
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
StringBuilder ans = new StringBuilder();
for (;;) {
int n = Integer.parseInt(sc.readLine());
if (n == 0)
break;
HashSet<String> set = new HashSet<>();
String[] arr = new String[n];
int[] codes = new int[n];
for (int x = 0; x < n; x++) {
arr[x] = sc.readLine();
codes[x] = hash(arr[x]);
set.add(arr[x]);
}
int count = 0;
for (int a = 0; a < arr.length - 1; a++)
for (int b = a + 1; b < arr.length; b++)
if (codes[a] == codes[b] && !arr[a].equals(arr[b]))
count++;
ans.append(set.size()).append(' ').append(count).append('\n');
}
System.out.print(ans);
}
static int hash(String s) {
int h = s.charAt(0);
for (int x = 1; x < s.length(); x++)
h ^= s.charAt(x);
return h;
}
}