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

IanSwartz
New poster
Posts: 6
Joined: Wed Sep 18, 2013 11:44 am

Re: 10945 - Mother Bear WA why? Anyone help me please

Post by IanSwartz » Wed Sep 18, 2013 6:55 pm

Hi, getting runtime error on Uva but it runs fine on my pc with correct output from testcases found here...

nevermind, solved!

B_sayem
New poster
Posts: 7
Joined: Wed Dec 11, 2013 7:57 pm

Re: 10945 - Mother Bear WA why? Anyone help me please

Post by B_sayem » Wed Dec 18, 2013 4:51 pm

Code: Select all

Thanx ,,got AC
:D :D :D
Last edited by B_sayem on Thu Dec 19, 2013 8:01 am, edited 1 time in total.

brianfry713
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

Post by brianfry713 » Thu Dec 19, 2013 1:34 am

It should be case insensitive.

Input:

Code: Select all

AbBa
Output should be:

Code: Select all

You won't be eaten!
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 10945 - Mother Bear WA why? Anyone help me please

Post by mobarak.islam » Tue Dec 24, 2013 10:54 am

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;
}

brianfry713
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

Post by brianfry713 » Wed Jan 15, 2014 12:41 am

PM sent
Check input and AC output for thousands of problems on uDebug!

terry646623
New poster
Posts: 8
Joined: Fri Jan 17, 2014 3:35 pm

Re: 10945 - Mother Bear WA why? Anyone help me please

Post by terry646623 » Mon Feb 24, 2014 2:12 pm

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.

brianfry713
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

Post by brianfry713 » Mon Feb 24, 2014 11:02 pm

Add this before line 133: compare1[new_length] = compare2[new_length] = '\0';
Check input and AC output for thousands of problems on uDebug!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

10945 - Mother bear Compile error

Post by NAbdulla » Wed Aug 06, 2014 2:34 pm

:roll:
Last edited by NAbdulla on Wed Aug 06, 2014 5:36 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10945 - Mother bear Compile error

Post by lighted » Wed Aug 06, 2014 3:55 pm

You can see reason of CE here in My Submissions:
http://uva.onlinejudge.org/index.php?op ... n=13999115

It is because of strlwr.
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.
Maybe Judge's compiler doesn't have it.

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;
}
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

Re: 10945 - Mother bear Compile error

Post by NAbdulla » Wed Aug 06, 2014 5:34 pm

Thanks a lot. After using userdefined function for that it is ACCEPTED. Thanks.

bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

Re: 10945 - Mother bear

Post by bgcsaif » Tue Sep 30, 2014 10:57 am

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.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10945 - Mother bear

Post by brianfry713 » Tue Sep 30, 2014 2:06 pm

You can see the reason for your CE by clicking "My Submissions".

Don't use strrev()
Check input and AC output for thousands of problems on uDebug!

bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

Re: 10945 - Mother bear

Post by bgcsaif » Sat Oct 04, 2014 6:41 am

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! :(

iliketocode
New poster
Posts: 1
Joined: Sun Oct 26, 2014 1:24 am

Re: 10945 - Mother bear

Post by iliketocode » Sun Oct 26, 2014 1:38 am

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;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10945 - Mother bear

Post by lighted » Sun Oct 26, 2014 9:54 am

Try to check input in this thread before posting.
jan_holmes wrote:Try this testcase :
.!?,As.,!?i I!!!,S,,a

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

Hope it helps... :)
Input

Code: Select all

M..a..d..a..m, Im adam!
DONE
Acc Output

Code: Select all

You won't be eaten!
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 109 (10900-10999)”