489 - Hangman Judge

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

Moderator: Board moderators

Is this a rule of Hangman? ;)

Yesss...
4
44%
Are you Crazy??? :P
5
56%
 
Total votes: 9

linux
Learning poster
Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm
Location: CA-95054
Contact:

Re: confuse 489 with online judge

Post by linux »

What is the output for input
1
cheese
ch
Solving for fun..
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: confuse 489 with online judge

Post by lnr »

Hi linux.

Input:

Code: Select all

1
cheese
ch
-1
Output:

Code: Select all

Round 1
You chickened out.
HugoMarques.ufcg
New poster
Posts: 1
Joined: Thu Oct 16, 2008 2:18 pm

Re: 489 WA: Need Help

Post by HugoMarques.ufcg »

Hello everyone, im getting TLE doesn´t matter what i am doing... can someone help me to optimize this code?

Code: Select all

import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {

   public static void main(String[] args) throws Exception {
	   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       String s1 = in.readLine();       
       while (!s1.equals("-1") ) {
           int roundNo = Integer.parseInt(s1);
           String palavra = in.readLine();
           int[] word = new int[26];
           int counterSucess = 0;
           for (int i = 0; i < palavra.length(); i++) {              
               word[palavra.charAt(i)-97]++;
               counterSucess++;
           }         
           String advinhacao = in.readLine();           
           int counterError = 0;
           boolean[] letters = new boolean[26];
           for (int i = 0; i < advinhacao.length(); i++) {
               Character c = advinhacao.charAt(i);
               int indice = c-97;
               if (!letters[indice]) {               
	               if (word[indice]!=0) {
	            	   counterSucess -= word[indice];
	            	   word[indice] = 0;
	            	   letters[indice]= true;
	               } else {
	            	   counterError++;
	            	   letters[indice]= true;
	               }	               
               }
               if (counterError == 7) break;               
               if (counterSucess==0) break;
           }
           System.out.println("Round " + roundNo);
           if (counterError == 7)
               System.out.println("You lose.");
           else if (counterSucess == 0)
               System.out.println("You win.");
           else System.out.println("You chickened out.");
           s1 = in.readLine();
       }
   }  
}
RoMeLuKo
New poster
Posts: 7
Joined: Mon Jan 02, 2006 1:44 am
Location: Puno - Peru
Contact:

489 Hangman J. - Many testcases that are very very critical

Post by RoMeLuKo »

Is a collection from several posts.
I hope that help you.
Works fine in my AC code.

Input:

Code: Select all

1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
4
rommel
romlnptuyq
5
rommel
romlnptuyqw
6
casa
ca
7
otorrinolaringologia
otr
8
peru
abcdefghijklmno
9
lastima
la
10
aaaaaaaaaaaaaaaaaaaaaa
a
11
bobobobobobobo
b
12
lalalalabababababaaaaa
alhhhhhhhhhhhhhhhhhhhhhhh
13
lkjaskljfkjklsalsdjfslkjfjf
dfklsdfskld
14
nbmbmmbnbbmbmbmbmnbnbnbmbmmbbnbnnbmbmbmboffiifififififfiif
ppppppppppppppppppppppppppppppppppwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrrrrb
15
abcdefggegegegegegege
gegegegegddabacecevbbdbdnndnenjejje
16
diccionariosdeportugues
dcptgiowqqqaazzxxxx
17
b
c
18
kljfdsjfoieoijefnvnenvionewveinvewv
dkdjjshue
19
ooooooooooooopppppppppppppppppppppeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwtttttttttttttttttt
operwt
20
ooooooooooooopppppppppppppppppppppeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwtttttttttttttttttt
operwqzxcvbnmklo
21
ploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploplo
jslkfsdjfsjfljfsdjfkdsjkjflkf
22
añoañoañoañoañoañoañoañoañoañoañoañoañoañoañoperuperuperuperuperuperuperuperuperuañoañoañoañoañoañoañoañoañoaño
añoperu
23
añoañoañoañoañoañoañoañoañoañoañoañoañoañoañoperuperuperuperuperuperuperuperuperuañoañoañoañoañoañoañoañoañoaño
ududududuudududupepeppewguqwhuihewhepqwehuwehwmncvmnnvmnvcnb
4
t
r
1
aaa
bcdbcdbcdbcdefghja
7
aaa
bcdbcdbcdbcdefdta
2
aaa
bcdbcdbcdbcdegt
1
cheese
ch
1
z
abcdef
1
aaa
bcdbcdbcdbcdefghja
7
aaa
bcdbcdbcdbcdefdta
2
aaa
bcdbcdbcdbcdegt
167
axyq
eprxibexxyf
171
nho
tonpyzwotkg
1
z
abcdef
1
abcdef
aghijklmcdefb
2
abcdef
abcdklmnoegfi
3
abcdef
abcklmnopdf
-1
Output:

Code: Select all

Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
Round 4
You chickened out.
Round 5
You lose.
Round 6
You chickened out.
Round 7
You chickened out.
Round 8
You lose.
Round 9
You chickened out.
Round 10
You win.
Round 11
You chickened out.
Round 12
You chickened out.
Round 13
You chickened out.
Round 14
You chickened out.
Round 15
You chickened out.
Round 16
You chickened out.
Round 17
You chickened out.
Round 18
You chickened out.
Round 19
You win.
Round 20
You lose.
Round 21
You chickened out.
Round 22
You win.
Round 23
You lose.
Round 4
You chickened out.
Round 1
You lose.
Round 7
You win.
Round 2
You chickened out.
Round 1
You chickened out.
Round 1
You chickened out.
Round 1
You lose.
Round 7
You win.
Round 2
You chickened out.
Round 167
You chickened out.
Round 171
You lose.
Round 1
You chickened out.
Round 1
You lose.
Round 2
You win.
Round 3
You chickened out.
Luck!
SundanCe
New poster
Posts: 1
Joined: Tue Nov 10, 2009 9:39 am

Also check this inputs

Post by SundanCe »

if user win the game you should break the loop immediately! I got WA because of this! :lol:

INPUT:
1
a
absdfghjklrtygfhfghfdhgfjhgvjybnmbmbnc
2
a
hgfhgfhgfhnmvciuypiaqwe

OUTPUT:
Round 1
You win.
Round 2
You lose.
shumphreys
New poster
Posts: 6
Joined: Wed Mar 21, 2007 7:24 pm

NOOB - question re INput and Output

Post by shumphreys »

Hi,
Prob a daft question but I keep stumbing over it ... :-(

If Input says (e.g. 489 Hangman Judge)
1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
-1

with Output:
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.

Does this mean that each set of input data be gathered and processed an then output the result; OR Get first set of data, output result, get second set of data, output result e.g.:
1
cheese
chese
Round 1
You win.

etc..

Thanks
Carlos
System administrator
Posts: 1286
Joined: Sat Oct 13, 2001 2:00 am
Location: Valladolid, Spain
Contact:

Re: NOOB - question re INput and Output

Post by Carlos »

You can do as you like. Input and output are different streams.
DON'T PM ME --> For any doubt, suggestion or error reporting, please use the "Contact us" form in the web.
Jambura
New poster
Posts: 1
Joined: Fri Nov 12, 2010 5:46 am

Re: 489 Hangman J. - Many testcases that are very very criti

Post by Jambura »

can anyone please say what size of array is required for this problem?
Thanks in advance :)
tiagoalex
New poster
Posts: 2
Joined: Thu Jan 05, 2012 1:43 am

489 - Hangman Judge (why Time Limit?)

Post by tiagoalex »

hello! im kind of new here, i was trying to solve this problem in Java but i got a time limit exceeded :/
can anyone tell me why?

Code: Select all

import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		ArrayList<String> array = new ArrayList<String>();
		ArrayList<String> arrayAux = new ArrayList<String>();
		char correctWord [];
		String tryWord;
		boolean wiiin = false;
		boolean looose = false;
		int round;
		int trie = 0;
		int wrongTries = 0;
		String win = "You win.";
		String loose = "You lose.";
		String pussy = "You chickened out.";
		
		while((round = in.nextInt())!=-1){
			correctWord=in.next().toCharArray();
			tryWord=in.next();
			for(int i=0; i<correctWord.length; i++){
				array.add(Character.toString(correctWord[i]));
			}
			boolean aux = false;
			String aux2 = "";
			while(wrongTries < 7 && trie < tryWord.length() && wiiin == false){
				aux2 = Character.toString(tryWord.charAt(trie));
				
				while(array.remove(aux2)){
					aux=true;
				}
				if(aux==false && !arrayAux.contains(aux2))
					wrongTries++;
				if(array.size()==0)
					wiiin=true;
				if(wrongTries == 7)
					looose=true;
				
				arrayAux.add(aux2);
				aux=false;
				trie++;	
			}
			System.out.println("Round "+round);
			if(wiiin)				
				System.out.println(win);
			else if(looose)
				System.out.println(loose);
			else
				System.out.println(pussy);
			
			//System.out.println(array.toString());
			array.clear();
			arrayAux.clear();
			wiiin = false;
			looose = false;
			trie = 0;
			wrongTries = 0;
		}
	}

}
thanks in advance!

cumps.
sornaCse
New poster
Posts: 6
Joined: Thu Jul 26, 2012 9:40 am

489 - Hangman Judge

Post by sornaCse »

I can't understand the condition number 6 of hangman. Please help me to understand the condition number 6.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 489 - Hangman Judge

Post by brianfry713 »

Input:

Code: Select all

2
cheese
abcdefg
c and e are correct, but h and s have not yet been guessed, so you don't win.
a, b, d, f, and g are wrong, but 5 wrong guesses is less than the 7 required to lose.
If you don't win or lose, you chicken out.
Check input and AC output for thousands of problems on uDebug!
Sabiha_Fancy
New poster
Posts: 24
Joined: Mon Jul 16, 2012 3:43 pm

Re: 489 - Hangman Judge (WA)

Post by Sabiha_Fancy »

I am getting wrong answer each time i submit it. Can anyone help me to understand the problem? I tried to find out the problem but failed.
here is my code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 1000

int main()
{
int n,hangman,success,len,count,flag,i,hang_flag;
char solution[SIZE],temp[SIZE],hang[SIZE];
char ch;

while(scanf("%d",&n)==1 && n != -1)
{
fflush(stdin);
gets(solution);
len = strlen(solution);
hangman = success = count = 0;
for(i=0; i<len; ++i)
temp = '0';
while(scanf("%c",&ch))
{
if(ch == '\n')
break;
flag = hang_flag = 0;
if(ch>='a' && ch<='z')
{
for(i=0; i<len; ++i)
{
if(ch == solution)
{
if(temp == '0')
{
temp = '1';
success++;
flag = 1;
}
else if(temp == '1')
{
flag = 1;
}
}
}
if(flag == 0)
{
if(count>0)
{
for(i=0; i<count; ++i)
{
if(hang == ch)
hang_flag = 1;
}
if(hang_flag == 0)
{
hangman++;
hang[count] = ch;
count++;
}
}
else
{
hangman++;
hang[count] = ch;
count++;
}
}
if(hangman == 7 || success == len)
{
fflush(stdin);
break;
}
}
}
printf("Round %d\n",n);
if(success == len)
printf("You win.\n");
else if(hangman == 7)
printf("You lose.\n");
else if(success<len && hangman<7)
printf("You chickened out.\n");
fflush(stdin);
}
return 0;
}
Fancy
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 489 - Hangman Judge (why Time Limit?)

Post by brianfry713 »

Doesn't match the sample I/O:
https://ideone.com/qEESt
Check input and AC output for thousands of problems on uDebug!
sdipu
New poster
Posts: 23
Joined: Sun May 19, 2013 1:50 am

Re: 489 WA: Need Help

Post by sdipu »

Please check my code. I tried almost all the input I got, but no luck. It showed wrong answer at-least hundreds of time. I am at a loss. Please help

Code: Select all

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

char word[200], inp[100], check[200];

int main()
{ 
    int k, f, w, i;
    while(scanf("%d ", &k) != EOF && k != -1)
    {
        memset(word, 0, sizeof(word));
        memset(check, 0, sizeof(check));

        gets(inp);
        for(i = 0; inp[i]; ++i)
            word[inp[i]] = 1;

        gets(inp);
        for(i = 0; inp[i]; ++i)
            check[inp[i]] = 1;

        for(i = 'a', w = f = 0; i <= 'z'; ++i)
            if(check[i])
                if(word[i])
                    word[i] = 0;
                else ++w;
            else if(word[i]) ++f;

        printf("Round %d\n", k);
        if(f)
            if(w >= 7) puts("You lose.");
            else puts("You chickened out.");
        else puts("You win.");

    }

    return 0;
}

PS: I tried these inputs:

Code: Select all

1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
1
aaa
bcdbcdbcdbcdefghja
-7
aaa
bcdbcdbcdbcdefdta
-2
aaa
bcdbcdbcdbcdegt
1
abc
bbbbbbbca
167
axyq
eprxibexxyf
171
nho
tonpyzwotkg
1
cheese
ch
1
z
abcdef
1
abcdef
ghijklm
-1
and got these outputs:
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
Round 1
You win.
Round -7
You win.
Round -2
You chickened out.
Round 1
You win.
Round 167
You chickened out.
Round 171
You lose.
Round 1
You chickened out.
Round 1
You chickened out.
Round 1
You lose.
Check out UVA Arena - a software build for UVA solvers @ http://dipu-bd.github.io/UVA-Arena/
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 489 WA: Need Help

Post by brianfry713 »

Input:

Code: Select all

1
a
qwertyua
Correct output:

Code: Select all

Round 1
You lose.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 4 (400-499)”