public class Finder {
public static void main(String[] args) throws IOException {
int[] array = new int[1000];
//заполняем массив
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = 0;
int elements = array.length;
int lowerBound = 0;
int upperBound = elements - 1;
int curIn;
int step = 0;
boolean isFounded = false;
while (true) {
System.out.println(upperBound - lowerBound);
curIn = (lowerBound + upperBound) / 2 ;
System.out.println("Is it more than " + array[curIn] + " ?");
String answer = br.readLine();
if(lowerBound> upperBound)
{
System.out.println(array[curIn]);
isFounded = true;
}
else if(upperBound - lowerBound == 1)
{
System.out.println(array[curIn]);
isFounded = true;
}
else if(upperBound - lowerBound == 0)
{
System.out.println(array[curIn]);
isFounded = true;
}
else
{
if (answer.equals("Yes"))
{
lowerBound = curIn + 1;
}
else if (answer.equals("No"))
{
upperBound = curIn - 1;
}
}
if(isFounded)break;
step++;
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
public class Finder {
public static void main(String[] args) throws IOException {
int[] array = fillArray();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int elements = array.length;
int lowerBound = 0;
int upperBound = elements - 1;
int curIn;
int step = 0;
Set<Integer> integerSet = new HashSet<>();
while (true) {
curIn = (lowerBound + upperBound) / 2;
/*if (lowerBound > upperBound) {
System.out.println("You are lying!Your number is " + array[curIn]);
break;
}*/
if (integerSet.size() == 1000) {
System.out.println("Your number is " + array[curIn]);
System.out.println(String.format("Computer used %s steps",step));
break;
} else if (integerSet.size() == 999) {
System.out.println("Your number is " + array[curIn + 1]);
System.out.println(String.format("Computer used %s steps",step));
break;
}
System.out.println(integerSet.size());
System.out.println(String.format("Is it more than %s ?", array[curIn]));
String answer = br.readLine();
if (answer.equals("Yes")) {
lowerBound = curIn + 1;
for (int i = array[curIn]; i > 0; i--) {
integerSet.add(array[i]);
}
} else if (answer.equals("No")) {
upperBound = curIn - 1;
for (int i = array[curIn]; i < 1000; i++) {
integerSet.add(array[i]);
}
}
step++;
}
}
public static int[] fillArray() {
int[] array = new int[1000];
for (int i = 0; i < 1000; i++) {
array[i] = i + 1;
}
return array;
}
}