Page 3 of 4

Re: confuse 489 with online judge

Posted: Thu Oct 09, 2008 12:30 pm
by linux
What is the output for input
1
cheese
ch

Re: confuse 489 with online judge

Posted: Thu Oct 09, 2008 1:15 pm
by lnr
Hi linux.

Input:

Code: Select all

1
cheese
ch
-1
Output:

Code: Select all

Round 1
You chickened out.

Re: 489 WA: Need Help

Posted: Thu Oct 16, 2008 2:21 pm
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();
       }
   }  
}

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

Posted: Mon Nov 02, 2009 7:27 am
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.

Also check this inputs

Posted: Tue Nov 10, 2009 9:43 am
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.

NOOB - question re INput and Output

Posted: Fri Dec 11, 2009 2:05 am
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

Re: NOOB - question re INput and Output

Posted: Sat Feb 13, 2010 2:18 pm
by Carlos
You can do as you like. Input and output are different streams.

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

Posted: Fri Nov 12, 2010 5:52 am
by Jambura
can anyone please say what size of array is required for this problem?
Thanks in advance :)

489 - Hangman Judge (why Time Limit?)

Posted: Fri Jan 06, 2012 4:14 am
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.

489 - Hangman Judge

Posted: Fri Jul 27, 2012 8:41 am
by sornaCse
I can't understand the condition number 6 of hangman. Please help me to understand the condition number 6.

Re: 489 - Hangman Judge

Posted: Sat Jul 28, 2012 12:01 am
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.

Re: 489 - Hangman Judge (WA)

Posted: Mon Sep 10, 2012 12:42 pm
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;
}

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

Posted: Mon Sep 10, 2012 10:51 pm
by brianfry713
Doesn't match the sample I/O:
https://ideone.com/qEESt

Re: 489 WA: Need Help

Posted: Sun Aug 25, 2013 2:34 am
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.

Re: 489 WA: Need Help

Posted: Tue Aug 27, 2013 2:47 am
by brianfry713
Input:

Code: Select all

1
a
qwertyua
Correct output:

Code: Select all

Round 1
You lose.