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

shauqi
New poster
Posts: 3
Joined: Fri Jan 02, 2015 1:51 pm

10945 - Mother bear

Post by shauqi »

Verdict: Compile error

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{
    char s[10000];
    while(gets(s))
    {
        if(strcmp(s,"DONE")==0) break;

        char s1[10000],s2[10000];
        int j=0;
        int i;
        for(i=0;i<strlen(s);i++)
        {
            if(isalpha(s[i]))
            {
                if(islower(s[i]))
                {
                    s1[j]=toupper(s[i]);
                    j++;
                }
                else
                {
                    s1[j]=s[i];
                    j++;
                }
            }
        }
        s1[j]='\0';
        strcpy(s2,s1);
        strrev(s2);
        if(strcmp(s2,s1)==0)
        {
            printf("You won't be eaten!\n");
        }
        else
        {
            printf("Uh oh..\n");
        }
    }
    return 0;
}

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

Re: 10945 - Mother bear

Post by lighted »

Try to post in existing thread. Use search by problem number (10945). Click on "My Submissions" to see reason of CE.

It's because of "isalpha", "islower" and "strrev". Add line

Code: Select all

#include <ctype.h>
strrev function is not available in standard gcc compiler. Write your own. See http://discuss.codechef.com/questions/1 ... c-compiler
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
shauqi
New poster
Posts: 3
Joined: Fri Jan 02, 2015 1:51 pm

Re: 10945 - Mother bear

Post by shauqi »

Thanks.. :)
coder21
New poster
Posts: 5
Joined: Tue Feb 10, 2015 9:13 am

10945 - Mother Bear

Post by coder21 »

Getting WA. Please help.
Following is the code:

Code: Select all

#include<stdio.h>
#include<string.h>
#define SIZE 1000


int palin(char a[SIZE],int length);

int main()
{
	//freopen("input.txt","r",stdin);	

	char a[SIZE];
	char b[SIZE];
	while( (gets(b)) )
	{   
		if( strcmp(b,"DONE") == 0 )
			break;
		int j=0;
		for(int i=0;i<strlen(b);i++)
		{
			if((b[i]>=65 && b[i]<=90) || (b[i]>=97 && b[i]<=122))
			{
				int val = b[i];
				if(val>90)
				{
					val = val - 97;
					a[j++]=65+val;
				}
				else
					a[j++]=b[i];
			}
		}
		a[j]='\0';
		int length,count,count1;

		 length=strlen(a)-1;

		count=palin(a,length);		

		if(count==1)printf("You won't be eaten!\n");
		else printf("Uh oh..\n");		
   }

	return 0;
}

int palin(char a[SIZE],int length)
{
	int len=length,index=0;
	while(index!=length)
	{
		if((len%2!=0) && (length-index==1) && (a[index]==a[length]))return(1);
		if(a[index]==a[length]){index++;length--;}
		else return(0);
	}
	if(index==length)
		return 1;
	else
		return 0;
}
Last edited by brianfry713 on Tue Feb 10, 2015 10:05 pm, edited 1 time in total.
Reason: Added code blocks
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10945 - Mother bear

Post by brianfry713 »

Next time post in the existing thread.
A blank line is considered a palindrome.
Check input and AC output for thousands of problems on uDebug!
meastman
New poster
Posts: 1
Joined: Fri Mar 04, 2016 9:59 pm

Re: 10945 - Mother bear

Post by meastman »

In case it helps anyone else, I spent a while trying to figure out why I was getting WA until I realized that the strings I copied and pasted from the problem description were wrong. The problem says to print "You won’t be eaten!", which contains U+2019 (RIGHT SINGLE QUOTATION MARK). However, you are expected to print "You won't be eaten!" with U+0027 (APOSTROPHE).
Post Reply

Return to “Volume 109 (10900-10999)”