10945 - Mother bear
Moderator: Board moderators
Re: 10945 - Mother Bear WA why? Anyone help me please
Hi, getting runtime error on Uva but it runs fine on my pc with correct output from testcases found here...
nevermind, solved!
nevermind, solved!
Re: 10945 - Mother Bear WA why? Anyone help me please
Last edited by B_sayem on Thu Dec 19, 2013 8:01 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10945 - Mother Bear WA why? Anyone help me please
It should be case insensitive.
Input:Output should be:
Input:
Code: Select all
AbBa
Code: Select all
You won't be eaten!
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 38
- Joined: Wed Dec 05, 2012 11:29 pm
Re: 10945 - Mother Bear WA why? Anyone help me please
I am getting WA here . Please help me .
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<cctype>
#include<cstdio>
#include<cstring>
int main()
{
char s[1000000];
int init,end;
bool des;
while(gets(s)&& strcmp(s,"DONE"))
{
des=false;
init=0;
end=strlen(s)-1;
while(init<=end)
{
if(!strcmp(s," "))
break;
while(init<=end && (s[init]<65 ||(s[init]>90 && s[init]<97)||s[init]>122))
init++;
while(end>=init && (s[end]<65 ||(s[end]>90 && s[end]<97)||s[end]>122))
end--;
if(s[init]>96)
s[init]-=32;
if(s[end]>96)
s[end]-=32;
if(s[init]!=s[end])
{
des=true;
break;
}
init++;
end--;
while(init<=end && (s[init]<65 ||(s[init]>90 && s[init]<97)||s[init]>122))
init++;
while(end>=init && (s[end]<65 ||(s[end]>90 && s[end]<97)||s[end]>122))
end--;
}
if(des)
printf("Uh oh..\n");
else
printf("You won't be eaten!\n");
memset(s,0,sizeof(s));
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10945 - Mother Bear WA why? Anyone help me please
PM sent
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 8
- Joined: Fri Jan 17, 2014 3:35 pm
Re: 10945 - Mother Bear WA why? Anyone help me please
Why I get wrong answer
Code: Select all
thanks! brianfry713.I got accepted. I finally know that Null is very important for string.
Last edited by terry646623 on Tue Mar 04, 2014 6:18 am, edited 2 times in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10945 - Mother Bear WA why? Anyone help me please
Add this before line 133: compare1[new_length] = compare2[new_length] = '\0';
Check input and AC output for thousands of problems on uDebug!
10945 - Mother bear Compile error

Last edited by NAbdulla on Wed Aug 06, 2014 5:36 pm, edited 1 time in total.
Re: 10945 - Mother bear Compile error
You can see reason of CE here in My Submissions:
http://uva.onlinejudge.org/index.php?op ... n=13999115
It is because of strlwr.
You can do your own strlower
Don't forget to remove your code after getting accepted. 
http://uva.onlinejudge.org/index.php?op ... n=13999115
It is because of strlwr.
Maybe Judge's compiler doesn't have it.I don't think either of those functions are part of the ANSI standard, so you might not have them depending on which compiler you are using.
You can do your own strlower
Code: Select all
#include <ctype.h>
char* strlower( char* s )
{
char* p = s;
while (*p = tolower( *p )) p++;
return s;
}

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 10945 - Mother bear Compile error
Thanks a lot. After using userdefined function for that it is ACCEPTED. Thanks.
Re: 10945 - Mother bear
Code: Select all
Removed after AC!!!
For other: DON'T USE strrev();
Last edited by bgcsaif on Sat Oct 04, 2014 6:33 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10945 - Mother bear
You can see the reason for your CE by clicking "My Submissions".
Don't use strrev()
Don't use strrev()
Check input and AC output for thousands of problems on uDebug!
Re: 10945 - Mother bear
Thanks. . . . I didn't know using strrev(); cause CE. . . . Just did it manually and it is done!
but feeling upset for this problem I had nearly 9 wrong attempt on UVA! 


-
- New poster
- Posts: 1
- Joined: Sun Oct 26, 2014 1:24 am
Re: 10945 - Mother bear
Not too sure why i keep getting WA.... hope someone can help me resolve this
Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 1000
int main(void){
char palindrome[MAX + 1] = {0};
int len, i, j, alpha;
while(fgets(palindrome, MAX, stdin)){
alpha = 0;
len = strlen(palindrome);
if(palindrome[len - 1] == '\n')
palindrome[len - 1] = '\0';
len = strlen(palindrome);
if(strcmp(palindrome, "DONE") == 0)
break;
for(i = 0; i < len; i++)
if(isalpha(palindrome[i]))
alpha++;
for(i = 0, j = len - 1; i < alpha/2; i++, j--){
if(isspace(palindrome[i]) || ispunct(palindrome[i]))
++i;
if(isspace(palindrome[j]) || ispunct(palindrome[j]))
--j;
if(toupper(palindrome[i]) != toupper(palindrome[j])){
printf("Uh oh..\n");
break;
}
}
if(i == alpha/2)
printf("You won't be eaten!\n");
}
return 0;
}
Re: 10945 - Mother bear
Try to check input in this thread before posting.
Acc Output
Don't forget to remove your code after getting accepted. 
Inputjan_holmes wrote:Try this testcase :
.!?,As.,!?i I!!!,S,,a
My Acc program output : Palindrome.
yours : not palindrome.
Hope it helps...
Code: Select all
M..a..d..a..m, Im adam!
DONE
Code: Select all
You won't be eaten!

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman