489 - Hangman Judge
Moderator: Board moderators
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
489 - Hangman Judge
I need more critical inputs for this problem... plzz, help.
Sajid Online: www.sajidonline.com
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
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 ...
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
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
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)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
:'(
i m really very sorry to say that, all this inputs show the correct result in my program. ![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
Sajid Online: www.sajidonline.com
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
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
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)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
hmm
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.
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
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
This sentence from problem descriptions says everything:
Dominik
PS. I read a few problems descriptions not so carefully, as I could. Maybe you are doing the same mistake![:)](./images/smilies/icon_smile.gif)
Code: Select all
Each unique wrong guess only counts against the contestant once.
PS. I read a few problems descriptions not so carefully, as I could. Maybe you are doing the same mistake
![:)](./images/smilies/icon_smile.gif)
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)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
Right, you are. ![:)](./images/smilies/icon_smile.gif)
thanxx, for ur kind advice. I'll try to read eVerYthinG from now On.![:D](./images/smilies/icon_biggrin.gif)
C ya
![:)](./images/smilies/icon_smile.gif)
thanxx, for ur kind advice. I'll try to read eVerYthinG from now On.
![:D](./images/smilies/icon_biggrin.gif)
C ya
Sajid Online: www.sajidonline.com
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
thanX aLL
hi all.
As i was bz for several days, I tried to fiX the problem right today, few minutes ago. AND I fixEd iT.
Thanx to all, sPecially,,, to Dominik Michniewski
thanx again.. c ya![:wink:](./images/smilies/icon_wink.gif)
As i was bz for several days, I tried to fiX the problem right today, few minutes ago. AND I fixEd iT.
![:D](./images/smilies/icon_biggrin.gif)
Thanx to all, sPecially,,, to Dominik Michniewski
thanx again.. c ya
![:wink:](./images/smilies/icon_wink.gif)
Sajid Online: www.sajidonline.com
-
- New poster
- Posts: 16
- Joined: Sun Mar 07, 2004 12:19 pm
- Location: Dhaka
489 why wa
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]
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??!
[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]
#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]
-
- Learning poster
- Posts: 55
- Joined: Sat Jan 24, 2004 9:30 pm
- Location: Chittagong
- Contact:
-
- Learning poster
- Posts: 55
- Joined: Sat Jan 24, 2004 9:30 pm
- Location: Chittagong
- Contact:
What?
They got all lose
?
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]
They got all lose
![:o](./images/smilies/icon_eek.gif)
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
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]
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]