-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessTheAnimal.java
More file actions
63 lines (62 loc) · 1.28 KB
/
GuessTheAnimal.java
File metadata and controls
63 lines (62 loc) · 1.28 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
54
55
56
57
58
59
60
61
62
63
import java.io.*;
import java.util.HashMap;
import java.util.Scanner;
public class GuessTheAnimal {
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(new File("guess.in"));
int num = scan.nextInt();
scan.nextLine();
int[][] traitTable = new int[num][200];
HashMap<String, Integer> traitToInd = new HashMap<String, Integer>();
String temp;
int n = 0;
int x = 0;
for (int i = 0; i < num; i++)
{
scan.next();
n = scan.nextInt();
for (int j = 0; j < n; j++)
{
temp = scan.next();
if (traitToInd.containsKey(temp))
{
traitTable[i][traitToInd.get(temp)] = 1;
}
else
{
traitToInd.put(temp, x);
traitTable[i][x] = 1;
x++;
}
}
scan.nextLine();
}
int[] traits1;
int[] traits2;
int common = 0;
int maxCommon = 0;
for (int i = 0; i < num-1; i++)
{
traits1 = traitTable[i];
for (int j = i+1; j < num; j++)
{
traits2 = traitTable[j];
for (int k = 0; k < x; k++)
{
if(traits2[k] == 1 && traits1[k] == 1)
common++;
}
if (common > maxCommon)
{
maxCommon = common;
}
common = 0;
}
}
PrintWriter bw = new PrintWriter(new BufferedWriter(new FileWriter("guess.out")));
bw.println(maxCommon+1);
scan.close();
bw.close();
}
}