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

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

489 - Hangman Judge

Post by Sajid »

I need more critical inputs for this problem... plzz, help.
Sajid Online: www.sajidonline.com
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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 ...
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

:'(

Post by Sajid »

i m really very sorry to say that, all this inputs show the correct result in my program. :cry:
Sajid Online: www.sajidonline.com
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

hmm

Post 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.
Sajid Online: www.sajidonline.com
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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 :)
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

Post by Sajid »

Right, you are. :)
thanxx, for ur kind advice. I'll try to read eVerYthinG from now On. :D

C ya
Sajid Online: www.sajidonline.com
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

thanX aLL

Post 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:
Sajid Online: www.sajidonline.com
Salmin Sultana
New poster
Posts: 16
Joined: Sun Mar 07, 2004 12:19 pm
Location: Dhaka

489 why wa

Post 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]
Thanatos
New poster
Posts: 5
Joined: Tue Mar 09, 2004 11:14 am

489 Compile Error??!

Post 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]
Thanatos
New poster
Posts: 5
Joined: Tue Mar 09, 2004 11:14 am

Post 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'
alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:

Post by alu_mathics »

Round 1
You lose.
Round 1
You lose.
Round 1
You lose.
cuii e
alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:

Post by alu_mathics »

Round 1
You lose.
Round 1
You lose.
Round 1
You lose.
cuii e
Thanatos
New poster
Posts: 5
Joined: Tue Mar 09, 2004 11:14 am

Post 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]
eth0
New poster
Posts: 3
Joined: Sun Sep 21, 2003 3:14 am

489 Hangman problem WA

Post 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]
Post Reply

Return to “Volume 4 (400-499)”