-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guess.java
43 lines (28 loc) · 947 Bytes
/
Guess.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
// open.kattis.com/problems/guess
// 2020-10-31
import java.util.Scanner;
public class Guess {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int guess = 500;
int max = 1000;
int min = 1;
System.out.println(guess);
while (true) {
String line = in.nextLine();
if (line.equals("lower")) {
max = guess-1;
guess = (max+min)/2;
System.out.println(guess);
System.out.flush();
} else if (line.equals("higher")) {
min = guess+1;
guess = (max+min)/2;
System.out.println(guess);
System.out.flush();
} else {
break;
}
}
}
}