Page 5 of 5

10945 - Mother bear

Posted: Fri Jan 02, 2015 9:13 pm
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;
}


Re: 10945 - Mother bear

Posted: Sat Jan 03, 2015 10:07 am
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

Re: 10945 - Mother bear

Posted: Tue Jan 13, 2015 5:15 am
by shauqi
Thanks.. :)

10945 - Mother Bear

Posted: Tue Feb 10, 2015 2:34 pm
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;
}

Re: 10945 - Mother bear

Posted: Tue Feb 10, 2015 10:06 pm
by brianfry713
Next time post in the existing thread.
A blank line is considered a palindrome.

Re: 10945 - Mother bear

Posted: Fri Mar 04, 2016 10:04 pm
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).