8
too high
10
right on
0
Moderator: Board moderators
import java.util.Scanner;
public class GuessingGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = 0;
String s = "";
int h = 0;
int y = 0;
int z = 0;
int oop = 0;
int[] x = new int[10];
int[] xx = new int[10];
for (int i = 0; i < 10; i++) {
x[i] = 0;
}
while (input.hasNext()) {
n = input.nextInt();
if (n == 0) {
break;
}
input.nextLine();
s = input.nextLine();
if (s.equals("too high")) {
xx[n - 1]++;
if (xx[n - 1] <= 2 && x[n - 1] == -1) {
oop = 1;
}
x[n - 1] = 1;
} else if (s.equals("too low")) {
xx[n - 1]++;
if (xx[n - 1] <= 2 && x[n - 1] == 1) {
oop = 1;
}
x[n - 1] = -1;
} else if (s.equals("right on")) {
if (x[n - 1] == 1 || x[n - 1] == -1) {
oop = 1;
}
x[n - 1] = 2;
for (int j = 0; j < x.length; j++) {
if (x[0] == 0) {
x[0] = -1;
} else if (x[9] == 0) {
x[9] = 1;
}
if (x[j] == 0 && x[j - 1] == 2) {
x[j] = 1;
} else if (x[j] == 0) {
x[j] = x[j - 1];
}
}
// //////////////y = 0,1//////////////
for (int i = n; i < x.length; i++) {
if (x[i] == 1) {
y = 1;
} else {
y = 0;
break;
}
}
// /////////////z = 0,1//////////
for (int i = 0; i < n - 1; i++) {
if (x[i] == -1) {
z = 1;
} else {
z = 0;
break;
}
}
// /////////////h = 1/////////
if (x[0] == 2) {
for (int i = 1; i < x.length; i++) {
if (x[i] == 1) {
h = 1;
} else {
h = -1;
break;
}
}
} else if (x[9] == 2) {
for (int i = 1; i < x.length - 1; i++) {
if (x[i] == -1) {
h = 1;
} else {
h = -1;
break;
}
}
}
int xxc = 0;
// ////////////////Special Cases///////////////////////
if (oop == 1) {
System.out.println("Stan is dishonest");
xxc = 1;
} else if (x[0] == 2 && h == 1) {
System.out.println("Stan may be honest");
xxc = 1;
} else if (x[0] == 2 && h == -1) {
System.out.println("Stan is dishonest");
xxc = 1;
} else if (x[9] == 2 && h == 1) {
System.out.println("Stan may be honest");
xxc = 1;
} else if (x[9] == 2 && h == -1) {
System.out.println("Stan is dishonest");
xxc = 1;
}
int oo = 0;
// /////////////////////////////
for (int i = 1; i < x.length - 1; i++) {
// if (x[i] == 2 && x[i - 1] == -1 && x[i + 1] == 1) {
if (x[i] == 2 && y == 1 && z == 1 && oop == 0) {
System.out.println("Stan may be honest");
oo = 0;
break;
} else {
oo = 1;
}
}
if (oo == 1 && oop == 0 && xxc == 0) {
System.out.println("Stan is dishonest");
}
// ///////////////////////////
for (int i = 0; i < x.length; i++) {
x[i] = 0;
}
oop = 0;
oo = 0;
xxc = 0;
}
}
}
}
Users browsing this forum: No registered users and 1 guest