Page 4 of 4

Re: 10530 - Guessing Game

Posted: Fri Jan 13, 2012 12:30 am
Remove this line:
freopen("in10530.txt","r",stdin);

Also print a newline at the end.

Re: 10530 - Guessing Game

Posted: Sat Aug 11, 2012 7:41 pm
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;
}

Re: 10530 - Guessing Game

Posted: Tue Aug 14, 2012 12:01 am
8
too high
10
right on
0

Re: 10530 - Guessing Game

Posted: Tue Nov 27, 2012 10:07 pm
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;

}

}

}
}

Re: 10530 - Guessing Game

Posted: Fri Nov 30, 2012 7:08 am

Re: 10530 - Guessing Game

Posted: Sun Jun 30, 2013 8:30 pm

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

Re: 10530 - Guessing Game

Posted: Tue Jul 02, 2013 12:58 am
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

10530 - Guessing Game Who help me? ;'(

Posted: Sat May 10, 2014 1:45 pm
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;
}

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

Posted: Mon May 12, 2014 10:28 pm
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

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

Posted: Thu May 22, 2014 11:30 am
brianfry713,
Thanks for sharing these test cases.

Re: 10530 - Guessing Game

Posted: Sun Jun 29, 2014 8:24 pm
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;

}

}

}

Re: 10530 - Guessing Game

Posted: Sun Jun 29, 2014 11:23 pm
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

Re: 10530 - Guessing Game

Posted: Tue Jul 01, 2014 4:30 pm
Thanks! Got AC