## 10530 - Guessing Game

All about problems in Volume 105. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10530 - Guessing Game

Remove this line:
freopen("in10530.txt","r",stdin);

Also print a newline at the end.
Check input and AC output for thousands of problems on uDebug!

Crocodile_009
New poster
Posts: 4
Joined: Thu Mar 08, 2012 8:11 am

### Re: 10530 - Guessing Game

i can't find out the reason why WA
plz help.
here is my code:

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
int ara[11],i,j,k=1,num,flag,c=0;
char k1[15],k2[15];

while(scanf("%d",&num)==1 && num!=0){
c=0;
for(i=0;i<10;i++){
ara=k;
k++;
}
while(c!=1){
scanf("%d",&num);
scanf("%s%s",&k1,&k2);
if(strcmp(k1,"too")==0 && strcmp(k2,"high")==0){
for(i=num;i<10;i++) ara=1;
c=0;
}
else if(strcmp(k1,"too")==0 && strcmp(k2,"low")==0){
for(i=num;i>0;i--) ara=1;
c=0;
}
/*if(strcmp(k1,"right")==0 && strcmp(k2,"on")==0)*/
else{
c=1;
if(ara[num]!=1) printf("Stan may be honest\n");
else
printf("Stan is dishonest\n");
}
}
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10530 - Guessing Game

8
too high
10
right on
0
Check input and AC output for thousands of problems on uDebug!

engnaruto
New poster
Posts: 2
Joined: Wed Nov 07, 2012 7:41 pm

### Re: 10530 - Guessing Game

hello
i made a code for this problem and the output of the program all is right but still WA
what should i do ?????

Code: Select all

``````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;

}

}

}
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10530 - Guessing Game

Check input and AC output for thousands of problems on uDebug!

jalil_cse
New poster
Posts: 8
Joined: Tue Dec 25, 2012 12:35 pm

### Re: 10530 - Guessing Game

Code: Select all

``````#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
int h=0,l=0,n,flag=0,flag1=0;
char s[20];
while(scanf("%d",&n)==1)
{
if(n==0)
break;
getchar();
gets(s);
if(strcmp(s,"too high")==0)
{
if(flag==0)
{
h=n;
flag=1;
}
else if (flag==1 && flag1==1)
{
if(l>=n)
{
h=n;
printf("Stan is dishonest\n");
}
else
{
h=n;
// printf("Stan may be honest\n");
}
}
}
else if(strcmp(s,"too low")==0)
{
if(flag1==0)
{
l=n;
flag1=1;
}
else if(flag==1 && flag1==1)
{
if(n>=h)
{
l=n;
printf("Stan is dishonest\n");
}
else
{
l=n;
// printf("Stan may be honest\n");
}
}
}
else if(strcmp(s,"right on")==0)
{
if(h>n && l<n)
{
printf("Stan may be honest\n");
h=0,l=0;
flag=0,flag1=0;
}
else if(flag==0 && flag1==0)
printf("Stan may be honest\n");
else if(flag==1 && flag1==0)
{
if(h>n)
printf("Stan may be honest\n");
else
{
printf("Stan is dishonest\n");
h=0,l=0;
flag=0,flag1=0;
}
}
else if(flag==0 && flag1==1)
{
if(n>l)
printf("Stan may be honest\n");
else
printf("Stan is dishonest\n");
h=0,l=0;
flag=0,flag1=0;
}
else
{
printf("Stan is dishonest\n");
h=0,l=0;
flag=0,flag1=0;

}
}
}
return 0;
}

``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10530 - Guessing Game

Input:

Code: Select all

``````3
right on
4
too high
9
right on
6
too low
9
too high
7
too high
7
too high
8
too low
5
too low
3
too low
1
too low
7
right on
7
right on
9
too high
7
too low
6
too low
5
too high
5
too low
2
right on
1
too low
6
right on
0
``````
AC output:

Code: Select all

``````Stan may be honest
Stan is dishonest
Stan is dishonest
Stan may be honest
Stan is dishonest
Stan may be honest
``````
Check input and AC output for thousands of problems on uDebug!

okokkook
New poster
Posts: 4
Joined: Wed Apr 30, 2014 1:55 pm

### 10530 - Guessing Game Who help me? ;'(

I cant find error help :'(

Code: Select all

``````#include <stdio.h>
#include <string.h>
int main(){
int n,down=1,up=10,flag=1;
while(scanf("%d",&n)!=EOF && n!=0){
getchar();
char s[20];
gets(s);
if(strcmp(s,"too high")==0){
if(n>=down && n<=up && n-1>=down && n-1<=up){
up=n-1;
}
else{
flag=0;
}

}
else if(strcmp(s,"too low")==0){
if(n>=down && n<=up && n+1>=down && n+1<=up){
down=n+1;
}
else{
flag=0;
}

}
else if(strcmp(s,"right on")==0){
if(n>=down && n<=up && flag==1){
printf("Stan may be honest\n");

}
else{
printf("Stan is dishonest\n");
}

down=1;
up=10;
flag=1;

}
}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10530 - Guessing Game Who help me? ;'(

Input:

Code: Select all

``````5
right on
6
too high
5
too high
7
too high
2
right on
4
too high
8
right on
6
too low
3
too low
8
too high
8
too low
5
too low
3
right on
2
too low
6
too high
9
right on
3
too high
9
too high
3
too low
4
too low
8
right on
0
``````
AC output:

Code: Select all

``````Stan may be honest
Stan may be honest
Stan is dishonest
Stan is dishonest
Stan is dishonest
Stan is dishonest
``````
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10530 - Guessing Game Who help me? ;'(

brianfry713,
Thanks for sharing these test cases.
Check input and AC output for over 7,500 problems on uDebug!

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

### Re: 10530 - Guessing Game

Hello, why is mine WA? I've been having the same outputs as those posted before

Code: Select all

``````#include <stdio.h>
#include <string.h>

int main(){

int good = 1;

int min = 1;
int max = 10;

while(1){

int d;

char buff[1000];
fgets(buff, 1000, stdin);
sscanf(buff, "%d", &d);

if(!d)
return 0;

fgets(buff, 1000, stdin);

if(!strcmp(buff, "too high\n")){
if( d < min ){
good = 0;
}
if( d < max ){
max = d - 1;
}
} else if (!strcmp(buff, "too low\n")) {
if (d > max){
good = 0;
}
if (d > min) {
min = d+1;
}
} else if (!strcmp(buff, "right on\n")) {

if(d>=min && d<=max && min <= max && good == 1 && max>=1 && max <=10 && min>=1 && min<=10){
printf("Stan may be honest\n");
} else {
printf("Stan is dishonest\n");
}

min = 1;
max = 10;
good = 1;

}

}

}
``````

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10530 - Guessing Game

jddantes wrote:Hello, why is mine WA? I've been having the same outputs as those posted before
You may try:

Input

Code: Select all

``````7
too high
1
too low
6
too high
6
right on
1
too low
3
too high
10
too high
1
right on
0
``````
Output

Code: Select all

``````Stan is dishonest
Stan is dishonest
``````

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Thanks! Got AC