Page 2 of 5

Posted: Fri Nov 23, 2007 8:47 pm
by Jan
I have sent you a PM.

Posted: Thu Feb 28, 2008 6:28 pm
by turcse143
I think there is a problem in here check it out.

Code: Select all

for(p=0,q=strlen(pal)-1;p<strlen(pal),q>=0;p++,q--)
      {
         if(pal[p]==pal[q])
            flag++;
         else
         {
            flag=-1;
            break;
         }
      } 
---take array size 50000.
---u skip other character
---build an array
---divided the array
--- compare if it is palindrom.
hope it helps

Kidding CE

Posted: Wed Jul 02, 2008 11:15 am
by Obaida
I can't understand why i have compilation error!!! :o
What is wrong with this??? Why this kidding with me???

Code: Select all

Done....

Re: 10945 - Mother Bear

Posted: Wed Jul 02, 2008 3:35 pm
by Jan
You can't use strrev(). Build it manually.

Re: 10945 - Mother Bear

Posted: Wed Jul 02, 2008 3:41 pm
by Obaida
Thanks a lot Vai.
Thanks a lot again for.....( not helping me):oops:
Do you know how much stupid i am?
I know!!! :wink:

Re: 10945 - Mother Bear

Posted: Wed Dec 10, 2008 11:40 am
by empo
I dont think there us any input like

Code: Select all

empoopme
done
DONE
because i got accepted and using tolower() for every char input and at last comparing my string with "done" not "DONE"..

Ouput i am having is
You won't be eaten!

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

This means program an be break at done or DONE..

10945 - run time error Mother Bear

Posted: Thu Jan 01, 2009 10:54 pm
by sazzadcsedu
whats wrong??
why runtime error??

Code: Select all


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


                         int  main()

						   {
                               int i,j,l,flag;
							   char str[10000],a,onlychar[10000],reonlychar[10000];
							   char words[52]={'a','b','c','d','e','f','g','h','i','j',
								 'k','l','m','n','o','p','q','r','s','t','u','v','w','x',
							  'y','z','A','B','C','D','E','F','G','H','I','J','K',
							'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
                              int array1[10000],array2[10000];
                        
						while(gets(str))
							
						{


                                memset(array1,0,sizeof(array1));
								memset(array2,0,sizeof(array2));


                   l=0;
				   j=0;
				   flag=1;
				                     if (!strcmp(str,"DONE"))
						  break;

                 
					for(i=0;i<=strlen(str)-1;i++)
					{ 
					   a=str[i];
                      
					   for(j=0;j<52;j++)
                          
					   {  
						   if(a==words[j])
						   {
							  
							   array1[l]=j%26;
                             onlychar[l]=a;
                              l++;
							
                             break;
						   }

                       }

					}   
					     onlychar[l]='\0';

                     j=0;
				
					  
						 
						 
						 
						 for(i=l-1;i>=0;i--)
					   { 
						   a=onlychar[i];
						   //printf("%c",a);
                           reonlychar[j]=a;
                       
                           j++;  
                           
					   }  
                      reonlychar[j]='\0';
 
                     l=0;

	               for(i=0;i<=strlen(reonlychar)-1;i++)
					{ 
					   a=reonlychar[i];
                      
					   for(j=0;j<52;j++)
                          
					   {  
						   if(a==words[j])
						   {
							   
							   array2[l]=j%26;
                             onlychar[l]=a;
                              l++;
							  
                             break;
						   }

                       }

					}   

                              










					      //printf("%d",j);
					     

						  for(i=0;reonlychar[i];i++)
						  {
 
                             //printf("%c",reonlychar[i]);

						  }
                             // printf("\n");
 
                              for(i=0;onlychar[i];i++)

							  {  

                                     

									  if(array1[i]!=array2[i])
									  { 
                                      
                                  
									     flag=0; 
									  }
								  
								       if(flag==0)

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

                      


								}

								return 0;
						   }


Re: 10945 - Mother Bear

Posted: Sat Jan 03, 2009 6:40 am
by Obaida
Check your array size it's a bit small, Causing RTE. :wink:

10945 - Mother Bear

Posted: Thu Jan 29, 2009 10:44 pm
by sazzadcsedu
why RTE??
MY code

Code: Select all

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


                  char str[200000],a,onlychar[200000],reonlychar[200000];
                  int array1[200000],array2[200000];

                         int  main()

						   {
                                int i,j,l,flag;
							   
							   char words[52]={'a','b','c','d','e','f','g','h','i','j',
								 'k','l','m','n','o','p','q','r','s','t','u','v','w','x',
							  'y','z','A','B','C','D','E','F','G','H','I','J','K',
							'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
                    
							   
							   // freopen("input.txt","r",stdin);
							   // freopen("output.txt","w",stdout);
						

                        
						while(gets(str))
							
						{


                                memset(array1,0,sizeof(array1));
								memset(array2,0,sizeof(array2));


                   l=0;
				   j=0;
				   flag=1;
				
             
 
			

                      if (!strcmp(str,"DONE"))
						  break;

                 
					for(i=0;i<=strlen(str)-1;i++)
					{ 
					   a=str[i];
                      
					   for(j=0;j<52;j++)
                          
					   {  
						   if(a==words[j])
						   {
							  
							   array1[l]=j%26;
                             onlychar[l]=a;
                              l++;
							  //printf("%c",words[j]);
                             break;
						   }

                       }

					}   
					     onlychar[l]='\0';

                     j=0;
						 //printf(onlychar);
						 //printf("\n");
					//printf("%d\n",strlen(onlychar));
						 //printf("%d",l);
					  
						 
						 
						 
						 for(i=l-1;i>=0;i--)
					   { 
						   a=onlychar[i];
						   //printf("%c",a);
                           reonlychar[j]=a;
                           //printf("%c",reonlychar[j]);
                           j++;  
                           
					   }  
                      reonlychar[j]='\0';
 
                     l=0;

	               for(i=0;i<=strlen(reonlychar)-1;i++)
					{ 
					   a=reonlychar[i];
                      
					   for(j=0;j<52;j++)
                          
					   {  
						   if(a==words[j])
						   {
							   
							   array2[l]=j%26;
                             onlychar[l]=a;
                              l++;
							  //printf("%c",words[j]);
                             break;
						   }

                       }

					}   

                              










					      //printf("%d",j);
					  
                         
 
                              for(i=0;onlychar[i];i++)

							  {  

                                     
                                     

									  if(array1[i]!=array2[i])
									  { 
                                  
                                   
									     flag=0; 
									  }
								  
								       if(flag==0)

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

								}

								return 0;
						   }


Re: 10945 - Mother Bear

Posted: Fri Jan 30, 2009 9:10 pm
by newkid
@sazzadcsedu

man.. your code indentation is horrible.. can you edit your post with proper indentation?

mother bear

Posted: Tue Sep 01, 2009 12:44 pm
by sayed
i cannot finding the solution for a long long time .I am getting wrong answer for many times.
here is my code any body help me..

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


int a,b,i,j,flag,len,k;
char ch[100],kh[100];

int main()
{
int p;
while(gets(ch)!=NULL)
{
if(!strcmp(ch,"DONE"))
break;
for(i=0;ch;i++)
if (ch>='A' && ch<='Z')
ch=ch+32;

for(i=0,j=0;ch;i++)
if (isalpha(ch))
kh[j++]=ch;

for(i=j-1,k=0;i>=0;i--)
ch[k++]=kh;

flag=0;
for(i=0;i<k;i++)
{
if(ch!=kh[i])
{
flag=0;
break;
}
else
flag=1;
}
if(flag) printf("You won't be eaten!\n");
else printf("Uh oh..\n");

}

return 0;
}

Re: 10945 - Mother Bear

Posted: Sat Oct 10, 2009 8:56 pm
by sudipta
Help Please. 10945-Mother Bear

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char line[100];
	int len,i,j,l,k;
	while(gets(line))
	{
		if(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E')break;
		char test[100],x,rev[100];
		j=0;
		int p=0;
		len=strlen(line);
		if(len==0)printf("You won't be eaten!\n");
else{	for(i=0;i<len;i++)
		{
			x=tolower(line[i]);
			if(x<='z' && x>='a')
			{
				test[j]=x;
				j++;
				l=j;
			}
		}
		for(i=0,j=l-1;i<l,j>=0;i++,j--)
		{
				rev[i]=test[j];
		}
		for(k=0;k<l;k++)
		{
			if(test[k]!=rev[k])
			{
				p++;
				break;
			}
		}
		if(p>0) printf("Uh oh..\n");
		else printf("You won't be eaten!\n");
      p=0; }
	}
	return 0;
}
My code is giving the right outputs. But why WA?
Anybody help please.

10945- MOther Bear

Posted: Sat Oct 24, 2009 10:21 pm
by sudipta
Please anyone help me. :x
Here is my code. I got WA again and again.

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char line[100];
	int len,i,j,l,k;
	while(gets(line))
	{
		len=strlen(line);
		if((len==4)&&(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E'))break;
		char test[100],x,rev[100];
		j=0;
		int p=0;
		if(len==0)printf("You won't be eaten!\n");
else{	for(i=0;i<len;i++)
		{
			x=tolower(line[i]);
			if(x<='z' && x>='a')
			{
				test[j]=x;
				j++;
				l=j;
			}
		}
		for(i=0,j=l-1;i<l,j>=0;i++,j--)
		{
				rev[i]=test[j];
		}
		for(k=0;k<l;k++)
		{
			if(test[k]!=rev[k])
			{
				p++;
				break;
			}
		}
		if(p>0) printf("Uh oh..\n");
		else printf("You won't be eaten!\n");
      p=0; }
	}
	return 0;
}
PLeaaaaaaaaaasssssssssssssssseeeeeeeeeeeeeeeeee

Re: 10945 - Mother Bear

Posted: Thu Dec 02, 2010 1:13 am
by sms.islam
please help!!! why i am getting WA........
[c]


#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define max 50001

char ch[max], str[max] , str1[max] , ch1[max];

void RESULT()
{
int ptr = 0 ;
ptr = strcmp(str1,str);
if(ptr == 0 ) printf("You won't be eaten!");
else printf("Uh oh..");
}

int main(void)
{
while(gets(ch))
{
if(ch[0] =='D' && ch[1] =='O' && ch[2] == 'N' && ch[3] == 'E')
break;
int i , j = 0 , len = 0 , len1 = 0 , l = 0 , k ;
len = strlen(ch);
if(len == 0 ) printf("You won't be eaten!");
else
{
for ( i = 0 ; i < len ; i ++)
{
if((isalpha(ch)) || (ch == ',') || (ch == '.') || (ch == '?') ||(ch =='!'))
{
if(isalpha(ch))
{
if(isupper(ch))
ch = tolower(ch);

ch1[j] = ch;
j ++;
}
}
else
continue;
}
strcpy(str,ch1);
strcpy(str1,ch1);
len1 = strlen(str1);
for ( k = len1-1 ; k >= 0 ; k --)
{
str1[l] = str1[k]; l++;
}
RESULT();
}
printf("\n");
}
return 0;
}

[c]

please tell whats wrong with that code..........

Re: 10945 - Mother Bear

Posted: Mon Mar 14, 2011 3:04 am
by DD
sudipta wrote:Help Please. 10945-Mother Bear

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char line[100];
	int len,i,j,l,k;
	while(gets(line))
	{
		if(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E')break;
		char test[100],x,rev[100];
		j=0;
		int p=0;
		len=strlen(line);
		if(len==0)printf("You won't be eaten!\n");
else{	for(i=0;i<len;i++)
		{
			x=tolower(line[i]);
			if(x<='z' && x>='a')
			{
				test[j]=x;
				j++;
				l=j;
			}
		}
		for(i=0,j=l-1;i<l,j>=0;i++,j--)
		{
				rev[i]=test[j];
		}
		for(k=0;k<l;k++)
		{
			if(test[k]!=rev[k])
			{
				p++;
				break;
			}
		}
		if(p>0) printf("Uh oh..\n");
		else printf("You won't be eaten!\n");
      p=0; }
	}
	return 0;
}
My code is giving the right outputs. But why WA?
Anybody help please.
You should change your termination condition from:

Code: Select all

if(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E')break;
to:

Code: Select all

if(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E'&&line[4]==0)break;
Otherwise your program won't perform for input line "DONEENOD", which is a palindrome.

Good luck! :D