10945 - Mother bear
Moderator: Board moderators
-
- Learning poster
- Posts: 81
- Joined: Wed May 09, 2007 9:59 pm
- Location: (CSE,DU) Dhaka,Bangladesh
I think there is a problem in here check it out.
---take array size 50000.
---u skip other character
---build an array
---divided the array
--- compare if it is palindrom.
hope it helps
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;
}
}
---u skip other character
---build an array
---divided the array
--- compare if it is palindrom.
hope it helps
''I want to be most laziest person in the world''
Kidding CE
I can't understand why i have compilation error!!!
What is wrong with this??? Why this kidding with me???

What is wrong with this??? Why this kidding with me???
Code: Select all
Done....
Last edited by Obaida on Mon Dec 15, 2008 9:32 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 10945 - Mother Bear
You can't use strrev(). Build it manually.
Ami ekhono shopno dekhi...
HomePage
HomePage
Re: 10945 - Mother Bear
Thanks a lot Vai.
Thanks a lot again for.....( not helping me):oops:
Do you know how much stupid i am?
I know!!!
Thanks a lot again for.....( not helping me):oops:
Do you know how much stupid i am?
I know!!!

try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 10945 - Mother Bear
I dont think there us any input like
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..
Code: Select all
empoopme
done
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..
"Accepted" is my passion but RTE is my weakness.....
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
10945 - run time error Mother Bear
whats wrong??
why runtime error??
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;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10945 - Mother Bear
Check your array size it's a bit small, Causing RTE. 

try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
10945 - Mother Bear
why RTE??
MY code
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;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10945 - Mother Bear
@sazzadcsedu
man.. your code indentation is horrible.. can you edit your post with proper indentation?
man.. your code indentation is horrible.. can you edit your post with proper indentation?
hmm..
mother bear
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;
}
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
Help Please. 10945-Mother Bear
My code is giving the right outputs. But why WA?
Anybody help please.
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;
}
Anybody help please.
Don't Copy, Think Also
10945- MOther Bear
Please anyone help me.
Here is my code. I got WA again and again.
PLeaaaaaaaaaasssssssssssssssseeeeeeeeeeeeeeeeee

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;
}
Don't Copy, Think Also
Re: 10945 - Mother Bear
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..........
[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..........
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10945 - Mother Bear
You should change your termination condition from:sudipta wrote:Help Please. 10945-Mother BearMy code is giving the right outputs. But why WA?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; }
Anybody help please.
Code: Select all
if(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E')break;
Code: Select all
if(line[0]=='D'&&line[1]=='O'&&line[2]=='N'&&line[3]=='E'&&line[4]==0)break;
Good luck!

Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?