forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVa00340_MasterMindHints.java
More file actions
100 lines (84 loc) · 2.12 KB
/
Copy pathUVa00340_MasterMindHints.java
File metadata and controls
100 lines (84 loc) · 2.12 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package uva;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class UVa00340_MasterMindHints {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int t = 1;
while (true) {
int N = in.nextInt();
if (N == 0)
break;
int[] code = new int[N];
for (int i = 0; i < N; ++i)
code[i] = in.nextInt();
System.out.println("Game " + t + ":");
while (true) {
int[] guess = new int[N];
for (int i = 0; i < N; ++i)
guess[i] = in.nextInt();
if (guess[0] == 0)
break;
int strong = 0;
int weak = 0;
boolean[] seenCode = new boolean[N];
boolean[] seenGuess = new boolean[N];
for (int i = 0; i < N; ++i)
if (code[i] == guess[i]) {
++strong;
seenCode[i] = true;
seenGuess[i] = true;
}
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (i != j && !seenCode[i] && !seenGuess[j] && code[i] == guess[j]) {
++weak;
seenCode[i] = true;
seenGuess[j] = true;
}
System.out.println(" (" + strong + "," + weak + ")");
}
++t;
}
System.exit(0);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}