10945 - Mother bear

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

Moderator: Board moderators

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

10945 - Mother bear

Post by medv » Wed Oct 26, 2005 2:38 pm

Why WA? Help me to find test where I am wrong please!!!!

Code: Select all


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

char s[1000];        /// I tried here even 1000000, but still WA
int i,j;

int main(void)
{
  while(gets(s), strcmp(s,"DONE"))
  {
     i = j = 0;
     while(s[++i])
      if (isalpha(s[i])) s[++j] = s[i];
     for(i=0;i<j;i++,j--)
       if (tolower(s[i]) != tolower(s[j])) break;
     if (i>=j) printf("You won't be eaten!\n");
	 else printf("Uh oh..\n");
  }
  return 0;
}

SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan

Re: 10945 - WA!

Post by SRX » Wed Oct 26, 2005 4:23 pm

no test cases
Are you sure i & j ' s initial value = 0 ?
studying @ ntu csie

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

yes

Post by medv » Wed Oct 26, 2005 7:43 pm

yes - the program works correctly on all my tests

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

testcase...

Post by jan_holmes » Wed Oct 26, 2005 8:32 pm

Try this testcase :
.!?,As.,!?i I!!!,S,,a

My Acc program output : Palindrome.
yours : not palindrome.

Hope it helps... :)

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

Thank

Post by medv » Wed Oct 26, 2005 8:56 pm

O SORRY SRX!
You are right! I got Ac.
THANK to ALL!

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel » Wed Jan 04, 2006 7:45 pm

Hey, I get WA in this problem. Can someone post some inout/outputs please?

I tested my program with this:

Code: Select all

Madam, Im adam!
Roma tibi subito motibus ibit amor.
Me so hungry!
Si nummi immunis
.!?,As.,!?i I!!!,S,,a
t
at
Madam, I adam!
DONE
Output:

Code: Select all

You won't be eaten!
You won't be eaten!
Uh oh..
You won't be eaten!
You won't be eaten!
You won't be eaten!
Uh oh..
Uh oh..
Thanks.[/code]
Image

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

The answers are correct.

Post by medv » Wed Jan 04, 2006 8:46 pm

To Schutzstaffel:
The answers are correct.

Send me your code to my e-mail - I'll check your program.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Wed Jan 04, 2006 10:12 pm

Try this:

Code: Select all

Madam, Im adam! 
Roma tibi subito motibus ibit amor. 
Me so hungry! 
Si nummi immunis 
.!?,As.,!?i I!!!,S,,a 
t 
at 
done

DONE

Code: Select all

You won't be eaten!
You won't be eaten!
Uh oh..
You won't be eaten!
You won't be eaten!
You won't be eaten!
Uh oh..
Uh oh..
You won't be eaten!
Darko

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel » Wed Jan 04, 2006 10:32 pm

That input also gives me correct output :?

To medv: just emailed you the code.

Thank you both.
Image

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

Here is your mistake

Post by medv » Wed Jan 04, 2006 10:51 pm

Try this test:
aa

This is a palindrome, but your program says that no.

Schutzstaffel
New poster
Posts: 37
Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal

Post by Schutzstaffel » Wed Jan 04, 2006 10:58 pm

Thanks a lot, got AC now! :P
I forgot to complete that test case, I only checked if the string size was 2 but forgot to compare the chars to see if they were the same :oops:
Thanks.
Image

User avatar
tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

Post by tmdrbs6584 » Tue Mar 14, 2006 10:53 am

palindrome

deena sultana
New poster
Posts: 36
Joined: Mon Jun 19, 2006 5:43 pm
Location: Bangladesh
Contact:

10945 - Mother Bear

Post by deena sultana » Mon Jun 19, 2006 5:54 pm

somthing is wrong in my code, i dont know that. :cry: plz help me.

Is anybody there to help me???


WOW! i get AC.
THANK U SO MUCH emotional_blind.
U r so kind.
take care.
Last edited by deena sultana on Mon Jun 19, 2006 6:49 pm, edited 1 time in total.

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Mon Jun 19, 2006 6:14 pm

empty string shoud be considered as pelindrom


Code: Select all

for(int j=0,k=strlen(pal)-1;j<strlen(pal),k>=0;j++,k--) 
{ 
if(pal[j]==pal[k]) 
flag++; 


else 
{ 
flag=0; 
break; 
} 
} 
here in your code , for empty string flag =0


Code: Select all

if(flag>0) 
cout<<"You won't be eaten!"<<endl; 
else 
cout<<"Uh oh.."<<endl;} 
} 
and here if flag=0 prints Uh oh..

just change those part ..
in first part
change only 1 line

Code: Select all

else 
{ 
flag=-1; 
break; 
} 
}
and second part change one line

Code: Select all

if(flag>=0) 
another thing after get ACCEPTED dont forget to remove your code,

and it is a good practice to give your code in code tag
other wise it is difficult to read

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

10945-mother bear.///where i have to fix?

Post by apurba » Thu Nov 22, 2007 5:35 pm

where i have to fix in this code

Code: Select all



deleted after acc...........


		

Last edited by apurba on Tue Mar 11, 2008 5:06 pm, edited 1 time in total.

Code: Select all

keep dreaming...

Post Reply

Return to “Volume 109 (10900-10999)”