401 - Palindromes

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

blackheartadhar
New poster
Posts: 10
Joined: Mon Nov 04, 2013 10:14 am

Re: 401-Palindromes Why getting WA

Post by blackheartadhar » Thu Jun 26, 2014 3:41 pm

Thanks! AC!

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

Re: 401-Palindromes Why getting WA

Post by mgavin2 » Wed Jul 30, 2014 11:14 pm

Code: Select all

ac >_<
W(tf)A code that passes all the cases I throw at it. What's the very simple thing I'm missing?
Last edited by mgavin2 on Thu Jul 31, 2014 2:16 am, edited 1 time in total.
all that matters is AC

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

Re: 401-Palindromes Why getting WA

Post by lighted » Thu Jul 31, 2014 12:37 am

Code: Select all

    rev['F'] = ' ';
    rev['H'] = ' ';
    rev['I'] = 'I';
Where is letter 'G'? Wrong value for 'H'. It must be

Code: Select all

    rev['H'] = ' H';
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

Re: 401-Palindromes Why getting WA

Post by mgavin2 » Thu Jul 31, 2014 2:16 am

lighted wrote:

Code: Select all

    rev['F'] = ' ';
    rev['H'] = ' ';
    rev['I'] = 'I';
Where is letter 'G'? Wrong value for 'H'. It must be

Code: Select all

    rev['H'] = ' H';
thank you so much >_<
all that matters is AC

refatsardar
New poster
Posts: 6
Joined: Sat Jun 07, 2014 10:22 pm

Re: 401- Palindromes

Post by refatsardar » Fri Aug 08, 2014 8:23 am

I have passed all test case from forum.But I get always WA.
Could you please help me to find out my mistake?
Already got 3 WA :(
Here is my code:

Code: Select all

/*UVa 401-Palindromes
Time-*/
#include<stdio.h>
#include<string.h>
const char* GetReverse(char inp[25])
{
	char str[25];
	int i,len=strlen(inp);
	for(i=0;i<len;i++)
	{
		str[i] = inp[len-i-1];
	}
	str[i] = '\0';
	return str;
}
int main()
{
	char ch,str[25],mr[25],list[91];
	list['A'] = 'A';list['E'] = '3';list['H'] = 'H';list['I'] = 'I';list['J'] = 'L';list['L'] = 'J';
	list['M'] = 'M';list['O'] = 'O';list['S'] = '2';list['T'] = 'T';list['U'] = 'U';list['V'] = 'V';list['W'] = 'W';list['X'] = 'X';
	list['Y'] = 'Y';list['Z'] = '5';list['1'] = '1';list['2'] = 'S';list['3'] = 'E';list['5'] = 'Z';list['8'] = '8';
	int i,p,m;
	while(scanf("%s",&str)==1)
	{
		p = 0;
		m = 0;
		if(strcmp(str,GetReverse(str))==0)
			p = 1;
		for(i=0;i<strlen(str);i++)
		{
			ch = list[str[i]];
			if((ch >='A' && ch <='Z')||(ch >='1' && ch <='9'))
			{
				mr[i] = ch;
				m = 1;
			}
			else
			{
				m = 0;
				break;
			}
		}
		mr[i] = '\0';
		if(m)
		{
			if(strcmp(str,GetReverse(mr))!=0)
				m = 0;
		}
		printf("%s -- ",str);
		if(p==0 && m==0)
			printf("is not a palindrome.");
		else if(p && m==0)
			printf("is a regular palindrome.");
		else if(p==0 && m)
			printf("is a mirrored string.");
		else if(p && m)
			printf("is a mirrored palindrome.");
		printf("\n\n");
	}
	return 0;
}

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

Re: 401- Palindromes

Post by brianfry713 » Fri Aug 08, 2014 9:42 pm

When I compile it I get a warning that in function GetReverse address of local variable str returned.
Try changing it to:
void GetReverse(char str[25], char inp[25])
Check input and AC output for thousands of problems on uDebug!

refatsardar
New poster
Posts: 6
Joined: Sat Jun 07, 2014 10:22 pm

Re: 401- Palindromes

Post by refatsardar » Sat Aug 09, 2014 10:09 pm

Thanks brianfry713.got AC :)

c8555
New poster
Posts: 1
Joined: Sat Aug 23, 2014 11:27 pm

Re: 401- Palindromes

Post by c8555 » Sat Aug 23, 2014 11:33 pm

here's some examples of input's and his outputs.
I think these are the hardest ones
Input:

Code: Select all

2BBS
B2SB
BBB
BBBB
AAA
AAAA
HII
O
X
B
xX
b
0
AE
ISSEJML11JML322I
SV2OSV2
8SZSJYYL2528
NOTAPALINDROME 
ISAPALINILAPASI 
2A3MEAS 
ATOYOTA
3QE
Z55
Output:

Code: Select all

2BBS -- is not a palindrome.

B2SB -- is not a palindrome.

BBB -- is a regular palindrome.

BBBB -- is a regular palindrome.

AAA -- is a mirrored palindrome.

AAAA -- is a mirrored palindrome.

HII -- is not a palindrome.

O -- is a mirrored palindrome.

X -- is a mirrored palindrome.

B -- is a regular palindrome.

xX -- is not a palindrome.

b -- is a regular palindrome.

0 -- is a regular palindrome.

AE -- is not a palindrome.

ISSEJML11JML322I -- is a mirrored string.

SV2OSV2 -- is a mirrored string.

8SZSJYYL2528 -- is a mirrored string.

NOTAPALINDROME -- is not a palindrome.

ISAPALINILAPASI -- is a regular palindrome.

2A3MEAS -- is a mirrored string.

ATOYOTA -- is a mirrored palindrome.

3QE -- is a mirrored string.

Z55 -- is a mirrored string.

icansolve
New poster
Posts: 3
Joined: Sun Dec 21, 2014 12:18 pm

Re: 401 - Palindromes

Post by icansolve » Sun Dec 21, 2014 12:19 pm

Hey guys! I dun get why I get WA

Hopefully someone is able to help me :)

Code: Select all

 Removed after AC 
Last edited by icansolve on Sun Dec 28, 2014 7:34 am, edited 1 time in total.

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

Re: 401 - Palindromes

Post by lighted » Sun Dec 21, 2014 1:37 pm

Problem description says
In addition, after each output line, you must print an empty line.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

icansolve
New poster
Posts: 3
Joined: Sun Dec 21, 2014 12:18 pm

Re: 401 - Palindromes

Post by icansolve » Sun Dec 21, 2014 1:55 pm

Oh yes AC!! Thanks a lot man (:

fadedreamz
New poster
Posts: 1
Joined: Tue Feb 10, 2015 8:55 am

Re: 401- Palindromes

Post by fadedreamz » Tue Feb 10, 2015 9:08 am

c8555 wrote:here's some examples of input's and his outputs.
I think these are the hardest ones
Input:

Code: Select all

2BBS
B2SB
BBB
BBBB
AAA
AAAA
HII
O
X
B
xX
b
0
AE
ISSEJML11JML322I
SV2OSV2
8SZSJYYL2528
NOTAPALINDROME 
ISAPALINILAPASI 
2A3MEAS 
ATOYOTA
3QE
Z55
Output:

Code: Select all

2BBS -- is not a palindrome.

B2SB -- is not a palindrome.

BBB -- is a regular palindrome.

BBBB -- is a regular palindrome.

AAA -- is a mirrored palindrome.

AAAA -- is a mirrored palindrome.

HII -- is not a palindrome.

O -- is a mirrored palindrome.

X -- is a mirrored palindrome.

B -- is a regular palindrome.

xX -- is not a palindrome.

b -- is a regular palindrome.

0 -- is a regular palindrome.

AE -- is not a palindrome.

ISSEJML11JML322I -- is a mirrored string.

SV2OSV2 -- is a mirrored string.

8SZSJYYL2528 -- is a mirrored string.

NOTAPALINDROME -- is not a palindrome.

ISAPALINILAPASI -- is a regular palindrome.

2A3MEAS -- is a mirrored string.

ATOYOTA -- is a mirrored palindrome.

3QE -- is a mirrored string.

Z55 -- is a mirrored string.
3QE
Z55

These two input's output is wrong in your sample
It should be -

Code: Select all

3QE -- is not a palindrome.

Z55 -- is not a palindrome.

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

401 - Palindromes

Post by coder21 » Tue Feb 10, 2015 9:24 am

I got WA. Please help. Following is my code:

Code: Select all

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


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

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

	char a[SIZE];
	char b[SIZE];
	while( (gets(b)) )
	{   
		int j=0;
		for(int i=0;i<strlen(b);i++)
		{
			if(b[i]!=' ')
				a[j++]=b[i];
		}
		a[j]='\0';
		int length,count,count1;

		 length=strlen(a)-1;

		count=palin(a,length);
		count1=mirror(a,length);

		if(count==1 && count1==1)printf("%s -- is a mirrored palindrome.\n\n",b);
		else if(count==1)printf("%s -- is a regular palindrome.\n\n",b);
		else if(count==0 && count1!=1)printf("%s -- is a not palindrome.\n\n",b);
		else if(count!=1 && count1==1)printf("%s -- is a mirrored string.\n\n",b);	
   }

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

int mirror(char a[SIZE],int length)
{
	char ch;
	int len=length,index=0,flag;

	while(index!=length)
	{
		if(len%2!=0 && length-index==1)
	    {
			flag=check(a,length,index);

			if(flag==1)return(1);
			else return(0);
	    }
		flag=check(a,length,index);

		if(flag==1){index++;length--;}
		else return(0);
	}

	if(index==length)
	{
		int stringLength = strlen(a);
		if(stringLength==1)
		{
			flag = check(a,length,index);
			return flag;
		}
		else return 1 ;
	}

	else
	  return(0);
}

int check(char a[SIZE],int length,int index)
{
	 if(a[index]=='A' && a[length]=='A')return(1);
	 else if(a[index]=='E' && a[length]=='E')return(1);
	 else if(a[index]=='H' && a[length]=='H')return(1);
	 else if(a[index]=='I' && a[length]=='I')return(1);
	 else if(a[index]=='J' && a[length]=='L')return(1);
	 else if(a[index]=='L' && a[length]=='J')return(1);
	 else if(a[index]=='M' && a[length]=='M')return(1);
	 else if(a[index]=='O' && a[length]=='O')return(1);
	 else if(a[index]=='S' && a[length]=='2')return(1);
	 else if(a[index]=='T' && a[length]=='T')return(1);
	 else if(a[index]=='U' && a[length]=='U')return(1);
	 else if(a[index]=='V' && a[length]=='V')return(1);
	 else if(a[index]=='W' && a[length]=='W')return(1);
	 else if(a[index]=='X' && a[length]=='X')return(1);
	 else if(a[index]=='Y' && a[length]=='Y')return(1);
	 else if(a[index]=='Z' && a[length]=='5')return(1);
	 else if(a[index]=='1' && a[length]=='1')return(1);
	 else if(a[index]=='2' && a[length]=='S')return(1);
	 else if(a[index]=='3' && a[length]=='E')return(1);
	 else if(a[index]=='E' && a[length]=='3')return(1);
	 else if(a[index]=='5' && a[length]=='Z')return(1);
	 else if(a[index]=='8' && a[length]=='8')return(1);
	 else return(0);
}
Last edited by brianfry713 on Tue Feb 10, 2015 9:56 pm, edited 1 time in total.
Reason: Added code blocks

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

401 - Palindromes

Post by coder21 » Tue Feb 10, 2015 9:38 am

I got WA. Please help.

Following is my code:

Code: Select all



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


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

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

char a[SIZE];
char b[SIZE];
while( (gets(b)) )
{ 
int j=0;
for(int i=0;i<strlen(b);i++)
{
if(b[i]!=' ')
a[j++]=b[i];
}
a[j]='\0';
int length,count,count1;

length=strlen(a)-1;

count=palin(a,length);
count1=mirror(a,length);

if(count==1 && count1==1)printf("%s -- is a mirrored palindrome.\n\n",b);
else if(count==1)printf("%s -- is a regular palindrome.\n\n",b);
else if(count==0 && count1!=1)printf("%s -- is a not palindrome.\n\n",b);
else if(count!=1 && count1==1)printf("%s -- is a mirrored string.\n\n",b);	
}

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

int mirror(char a[SIZE],int length)
{
char ch;
int len=length,index=0,flag;

while(index!=length)
{
if(len%2!=0 && length-index==1)
{
flag=check(a,length,index);

if(flag==1)return(1);
else return(0);
}
flag=check(a,length,index);

if(flag==1){index++;length--;}
else return(0);
}

if(index==length)
{
int stringLength = strlen(a);
if(stringLength==1)
{
flag = check(a,length,index);
return flag;
}
else return 1 ;
}

else
return(0);
}

int check(char a[SIZE],int length,int index)
{
if(a[index]=='A' && a[length]=='A')return(1);
else if(a[index]=='E' && a[length]=='E')return(1);
else if(a[index]=='H' && a[length]=='H')return(1);
else if(a[index]=='I' && a[length]=='I')return(1);
else if(a[index]=='J' && a[length]=='L')return(1);
else if(a[index]=='L' && a[length]=='J')return(1);
else if(a[index]=='M' && a[length]=='M')return(1);
else if(a[index]=='O' && a[length]=='O')return(1);
else if(a[index]=='S' && a[length]=='2')return(1);
else if(a[index]=='T' && a[length]=='T')return(1);
else if(a[index]=='U' && a[length]=='U')return(1);
else if(a[index]=='V' && a[length]=='V')return(1);
else if(a[index]=='W' && a[length]=='W')return(1);
else if(a[index]=='X' && a[length]=='X')return(1);
else if(a[index]=='Y' && a[length]=='Y')return(1);
else if(a[index]=='Z' && a[length]=='5')return(1);
else if(a[index]=='1' && a[length]=='1')return(1);
else if(a[index]=='2' && a[length]=='S')return(1);
else if(a[index]=='3' && a[length]=='E')return(1);
else if(a[index]=='E' && a[length]=='3')return(1);
else if(a[index]=='5' && a[length]=='Z')return(1);
else if(a[index]=='8' && a[length]=='8')return(1);
else return(0);
}
Last edited by brianfry713 on Tue Feb 10, 2015 9:55 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: 401 - Palindromes

Post by brianfry713 » Tue Feb 10, 2015 10:00 pm

Next time post in the existing thread, don't double post.

A3A -- is a regular palindrome.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 4 (400-499)”