Page 1 of 4

489 - Hangman Judge

Posted: Fri Feb 21, 2003 8:34 am
by Sajid
I need more critical inputs for this problem... plzz, help.

Posted: Fri Feb 21, 2003 9:12 am
by Dominik Michniewski
In my opinion this problem has not any critical input or output ....
Maybe you don't output correctly data ?
Check dot's, new lines, numbers of rounds .... This problem is straight forward to me ...
And last - Try to rewrite code - put to trash old and write new (but without looking at old version :) - in my case it's always work :)) or put this problem away for some time ....

Best luck
Dominik

PS. This is only my opinion ...

:'(

Posted: Fri Feb 21, 2003 11:06 am
by Sajid
i m really very sorry to say that, all this inputs show the correct result in my program. :cry:

Posted: Fri Feb 21, 2003 11:21 am
by Dominik Michniewski
Try this:

1
aaa
bcdbcdbcdbcdefghja
7
aaa
bcdbcdbcdbcdefdta
2
aaa
bcdbcdbcdbcdegt

output:
Round 1
You lose.

Round 7
You win.

Round 2
You chickened out.


Dominik

hmm

Posted: Fri Feb 21, 2003 11:26 am
by Sajid
then, here is problem... hmmmm

in my program, every output shows "You lose".

ok. but why this is "win" in 2nd case and "chikened out" in 3rd case???

plz, eXplain.

Posted: Fri Feb 21, 2003 12:00 pm
by Dominik Michniewski
This sentence from problem descriptions says everything:

Code: Select all

Each unique wrong guess only counts against the contestant once. 
Dominik

PS. I read a few problems descriptions not so carefully, as I could. Maybe you are doing the same mistake :)

Posted: Fri Feb 21, 2003 12:09 pm
by Sajid
Right, you are. :)
thanxx, for ur kind advice. I'll try to read eVerYthinG from now On. :D

C ya

thanX aLL

Posted: Wed Mar 05, 2003 4:09 am
by Sajid
hi all.

As i was bz for several days, I tried to fiX the problem right today, few minutes ago. AND I fixEd iT. :D

Thanx to all, sPecially,,, to Dominik Michniewski


thanx again.. c ya :wink:

489 why wa

Posted: Sun Mar 07, 2004 12:30 pm
by Salmin Sultana
why wa?
need some sample input&output
my coding:

[cpp]
#include<stdio.h>
#include<string.h>

int posn[258],travel[258],nmtrv[258];

int main()
{
long int num,i,in;
char str[10000],res[10000],s[5];
long int match=0,notm=0,len,len1;

for(;;)
{
scanf("%ld",&num);
gets(s);
if(num==-1)
break;

gets(str);
gets(res);
len=strlen(str);
len1=strlen(res);
match=0;
notm=0;

memset(posn,0,sizeof(int)*258);
memset(travel,0,sizeof(int)*258);
memset(nmtrv,0,sizeof(int)*258);

for(i=0;i<len;i++)
posn[str-97]++;

for(i=0;i<len1;i++)
{
in=res-97;

if((posn[in]==0)){
if(nmtrv[in]==0){
notm++;
nmtrv[in]=1;
}
}
else{
if(travel[in]==0){
match+=posn[in];
travel[in]=1;
}
}

if(notm==7){
printf("Round %ld\nYou lose.\n",num);
break;
}
else if(match==len){
printf("Round %ld\nYou win.\n",num);
break;
}
}
if(notm<7&&match!=len)
printf("Round %ld\nYou chickened out.\n",num);
}

return 0;
}[/cpp]

489 Compile Error??!

Posted: Wed Mar 10, 2004 2:39 pm
by Thanatos
[cpp]#include <iostream>
#include <string>

using namespace std;

int search(const char &a,const string &s)
{
for (int i=0;i<s.length();i++)
if (s==a) return i;
return -1;
}


inline int process(const string &s)
{
string temp; temp+=s[0];
for (int i=1;i<s.length();i++)
if (s[i-1]!=s && search(s,temp)==-1) temp+=s;
return temp.length();
}

int main()
{
int rn,i,dif;
string guess,attempts,s;
while (cin >> rn >> s >> guess)
{
if (rn==-1) break;
dif=process(s);
attempts="";
for (i=0;i<guess.length();i++)
{
if (attempts.length()==7 || dif==0) break;
if (search(guess,s)!=-1) dif--;
else if (search(guess,attempts)==-1) attempts+=guess;
}
printf("\nRound %d\n",rn);
if (attempts.length()==7) printf("You lose.\n\n");
else if (dif==0) printf("You win.\n\n");
else printf("You chickened out.\n\n");
}
return 0;
}
[/cpp]

Can anybody help me expalain how this would cause a compile error? And I compiled with GCC as well :S.[/cpp]

Posted: Wed Mar 10, 2004 2:58 pm
by Thanatos
Actually guys, nvm I found my problem. But now i get WA?

Can somebody explain please?

I tried inputs some Dominic guy gave me and they worked...

1
aaa
bcdbcdbcdbcdefgjt

gave me 'chickened out'

1
aaa
bcdbcdbcdbcdawer
gave me 'win'

1
aaa
bcdbcdbcdbcdqwertypl
gave me 'lost'

Posted: Wed Mar 10, 2004 8:33 pm
by alu_mathics
Round 1
You lose.
Round 1
You lose.
Round 1
You lose.

Posted: Wed Mar 10, 2004 8:35 pm
by alu_mathics
Round 1
You lose.
Round 1
You lose.
Round 1
You lose.

Posted: Thu Mar 11, 2004 10:35 am
by Thanatos
What?

They got all lose :o ?

Hrm...changed my code but i still get WA. And I'm pretty sure I got correct answers...at least on my compiler...(GCC)

[cpp]#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int search(const char &a,const string &s)
{
for (int i=0;i<s.length();i++)
if (s==a) return i;
return -1;
}

int main()
{
int rn,i,dif;
string guess,attempts,s,temp;
while (true)
{
cin >> rn;
if (rn==-1) return 0;
cin >> s >> guess;
temp+=s[0];
for (i=1;i<s.length();i++)
if (s[i-1]!=s && search(s,temp)==-1) temp+=s;
dif=temp.length();
attempts="";
for (i=0;i<guess.length();i++)
{
if (attempts.length()==7 || dif==0) break;
if (search(guess,s)!=-1) dif--;
else if (search(guess,attempts)==-1) attempts+=guess;
}
printf("\nRound %d\n",rn);
if (attempts.length()==7) printf("You lose.\n\n");
else if (dif==0) printf("You win.\n\n");
else printf("You chickened out.\n\n");
temp="";
}
return 0;
}
[/cpp][/cpp]

489 Hangman problem WA

Posted: Sun Apr 04, 2004 11:33 am
by eth0
Hi guys,

I'm also getting WA for this problem.

1. Should there be empty lines between every test cases in the output? The problem description doesn't say so, but some people's sample input seems so..

2. If there are multiple *correct* guesses, are these counted towards your *hangman strokes*? For example:

Round1
abc
bbbbbbbca

is this win or lose?

Dominik's example works perfect on mine, and the output format seems to be identical.. not sure what's wrong..

Here's the code:
[c]

#include <stdio.h>
#include <string.h>
#define MAX 1024

void solve_problem(void);

int main() {
solve_problem();
return 0;
}

void solve_problem(void) {
int count, found, round, t,i, j, win;
char answer[MAX], guess[MAX],guess2[26];;

scanf("%d\n", &round);
while(round!=-1) {
fgets(answer, MAX, stdin);
fgets(guess, MAX, stdin);
/*process*/
count=0;
found=0;
memset(guess2, 0x00, 26*sizeof(char));
/* printf("strlenofGuess:%d\n", strlen(guess));
printf("Guess:%s", guess);*/
for(i=0;i<strlen(guess)-1;i++) {
for(j=0;j<26;j++) {
if (guess2[j]==guess)
found=1;
}
if(found==0) {
guess2[count]=guess;
count++;
}
found=0;
}
/* printf("Guess2:%s", guess2);*/



if(strlen(guess2) < 7)
t=strlen(guess2);
else
t=7;


for(i=0;i<t;i++) {
for(j=0;j<strlen(answer)-1;j++) {
if(answer[j]==guess2)
answer[j]='Z';
}
}

win=0;
for(i=0;i<strlen(answer)-1;i++) {
if(answer!='Z')
win=1; /*win=1 if u lose*/
}
printf("Round %d\n", round);
if(win==0)
printf("You win.\n");
else if (strlen(guess2) <= 7)
printf("You chickened out.\n");
else
printf("You lose.\n");





memset(answer, 0x00, MAX*sizeof(char));
memset(guess, 0x00, MAX*sizeof(char));
scanf("%d\n", &round);
if(round!=-1) printf("\n");
}
}
[/c]