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

cse.komol
New poster
Posts: 1
Joined: Sun Sep 08, 2013 2:35 am

401-Palindromes Why getting WA

Post by cse.komol » Sun Sep 08, 2013 2:56 am

Please someone check this, why i am getting WA

Code: Select all

Removed After Accepted.
Last edited by cse.komol on Tue Sep 10, 2013 11:58 pm, edited 1 time in total.

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

Re: 401-Palindromes Why getting WA

Post by brianfry713 » Mon Sep 09, 2013 10:51 pm

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

Salsabil
New poster
Posts: 4
Joined: Tue Sep 10, 2013 1:43 pm

Re: 401-Palindromes Why getting WA

Post by Salsabil » Wed Sep 18, 2013 1:23 am

i've tried all the test cases here, still i'm getting wa.. please help. :(

here is my code:

http://paste.ubuntu.com/6121263/

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

Re: 401-Palindromes Why getting WA

Post by brianfry713 » Thu Sep 19, 2013 1:12 am

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

beboo
New poster
Posts: 2
Joined: Sat Feb 01, 2014 12:27 am

Re: 401-Palindromes Why getting WA

Post by beboo » Sat Feb 01, 2014 12:32 am

i need help with the code i dont know why i get WA


#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <string>
#include <string.h>
#include<algorithm>
#include <math.h>
#include <iomanip>
#include<stdio.h>
#define min(x,y) ((x)<(y)? x:y)
using namespace std;


int main()
{
//freopen("beboo.txt","r",stdin);
string S;
string L="AEHIJLMOSTUVWXYZ12358";
bool mir=false;
bool pal=false;
bool first =false;
int count=0; int count2=0;
int check=0;
while(cin>>S)
{
check=0;
pal=false;
mir=false;
int y=S.length();
int x=((y)/2);
int a=y-1; int b=0;
//cout<<S[0]<<" "<<S[S.length()-1]<<endl;

if(first==true)
// {cout<<endl;}
first=true;
count =0; count2=0;
for(int i=0;i<x;i++)
{
if (S[a]==S)
{count++;
count2++;

if(S[a]=='B'||S[a]=='C'||S[a]=='D'
||S[a]=='F'||S[a]=='G'||S[a]=='K'
||S[a]=='P'||S[a]=='Q'||S[a]=='R'
||S[a]=='4'||S[a]=='0'
||S[a]=='6'||S[a]=='7'||S[a]=='9'||S[a]=='E'||S[a]=='3'
||S[a]=='S'||S[a]=='2'
||S[a]=='Z'||S[a]=='5')
{mir=false;
count2--;}
for(int i=0;i<L.length();i++)
{if(S[a]!=L)
{check++;}
}
if(check==L.length())
{count2--;}


}
else
{
pal=false;

if(S[a]=='B'||S[a]=='C'||S[a]=='D'||S=='B'||S=='C'||S=='D'
||S[a]=='F'||S[a]=='G'||S[a]=='K'||S=='F'||S=='G'||S=='K'
||S[a]=='P'||S[a]=='Q'||S[a]=='R'||S=='P'||S=='Q'||S=='R'
||S[a]=='4'||S[b]=='4'||S[a]=='0'||S[b]=='0'
||S[a]=='6'||S[a]=='7'||S[a]=='9'||S[b]=='6'||S[b]=='7'||S[b]=='9')
{
mir=false;
break;
}
else if(S[a]=='E'&&S[b]=='3'||S[a]=='3'&&S[b]=='E'
||S[a]=='S'&&S[b]=='2'||S[a]=='2'&&S[b]=='S'
||S[a]=='Z'&&S[b]=='5'||S[a]=='5'&&S[b]=='Z'
)
{count2++;}

}
a--;
b++;
}
if(count==x)
{pal=true;}
if(count2==x)
{mir=true;}
if(y%2!=0)
{
int z=(y/2);
if(S[z]=='B'||S[z]=='C'||S[z]=='D'
||S[z]=='F'||S[z]=='G'||S[z]=='K'
||S[z]=='P'||S[z]=='Q'||S[z]=='R'
||S[z]=='4'||S[z]=='0'
||S[z]=='6'||S[z]=='7'||S[z]=='9')
{mir=false;}

}
if(y==1)
{
a=0;
if(S[a]=='B'||S[a]=='C'||S[a]=='D'
||S[a]=='F'||S[a]=='G'||S[a]=='K'
||S[a]=='P'||S[a]=='Q'||S[a]=='R'
||S[a]=='4'||S[a]=='0'
||S[a]=='6'||S[a]=='7'||S[a]=='9'||S[a]=='E'||S[a]=='3'
||S[a]=='S'||S[a]=='2'
||S[a]=='Z'||S[a]=='5')
{mir=false;}
}
if(pal==false&&mir==false)
{cout<<S<<" -- is not a palindrome.";}
else if(pal==false&&mir==true)
{cout<<S<<" -- is a mirrored string.";}
else if(pal==true&&mir==false)
{cout<<S<<" -- is a regular palindrome.";}
else
{cout<<S<<" -- is a mirrored palindrome.";}

cout<<endl;
cout<<endl;
}
return 0;

}//` ''

beboo
New poster
Posts: 2
Joined: Sat Feb 01, 2014 12:27 am

Re: 401- Palindromes

Post by beboo » Sat Feb 01, 2014 1:16 am

i need help with the code , plzzz x(
#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <string>
#include <string.h>
#include<algorithm>
#include <math.h>
#include <iomanip>
#include<stdio.h>
#define min(x,y) ((x)<(y)? x:y)
using namespace std;


int main()
{
//freopen("beboo.txt","r",stdin);
string S;
string L="AEHIJLMOSTUVWXYZ12358";
bool mir=false;
bool pal=false;
bool first =false;
int count=0; int count2=0;
int check=0;
while(cin>>S)
{
check=0;
pal=false;
mir=false;
int y=S.length();
int x=((y)/2);
int a=y-1; int b=0;
//cout<<S[0]<<" "<<S[S.length()-1]<<endl;

if(first==true)
// {cout<<endl;}
first=true;
count =0; count2=0;
for(int i=0;i<x;i++)
{
if (S[a]==S)
{count++;
count2++;

if(S[a]=='B'||S[a]=='C'||S[a]=='D'
||S[a]=='F'||S[a]=='G'||S[a]=='K'
||S[a]=='P'||S[a]=='Q'||S[a]=='R'
||S[a]=='4'||S[a]=='0'
||S[a]=='6'||S[a]=='7'||S[a]=='9'||S[a]=='E'||S[a]=='3'
||S[a]=='S'||S[a]=='2'
||S[a]=='Z'||S[a]=='5'||S[a]=='L'||S[a]=='J')
{mir=false;
count2--;}
for(int i=0;i<L.length();i++)
{if(S[a]!=L)
{check++;}
}
if(check==L.length())
{count2--;}


}
else
{
pal=false;

if(S[a]=='B'||S[a]=='C'||S[a]=='D'||S=='B'||S=='C'||S=='D'
||S[a]=='F'||S[a]=='G'||S[a]=='K'||S=='F'||S=='G'||S=='K'
||S[a]=='P'||S[a]=='Q'||S[a]=='R'||S=='P'||S=='Q'||S=='R'
||S[a]=='4'||S[b]=='4'||S[a]=='0'||S[b]=='0'
||S[a]=='6'||S[a]=='7'||S[a]=='9'||S[b]=='6'||S[b]=='7'||S[b]=='9')
{
mir=false;
break;
}
else if(S[a]=='E'&&S[b]=='3'||S[a]=='3'&&S[b]=='E'
||S[a]=='S'&&S[b]=='2'||S[a]=='2'&&S[b]=='S'
||S[a]=='Z'&&S[b]=='5'||S[a]=='5'&&S[b]=='Z'
||S[a]=='J'&&S[b]=='L'||S[a]=='L'&&S[b]=='J'
)
{count2++;}

}
a--;
b++;
}
if(count==x)
{pal=true;}
if(count2==x)
{mir=true;}
if(y%2!=0)
{
int z=(y/2);
if(S[z]=='B'||S[z]=='C'||S[z]=='D'
||S[z]=='F'||S[z]=='G'||S[z]=='K'
||S[z]=='P'||S[z]=='Q'||S[z]=='R'
||S[z]=='4'||S[z]=='0'
||S[z]=='6'||S[z]=='7'||S[z]=='9')
{mir=false;}

}
if(y==1)
{
a=0;
if(S[a]=='B'||S[a]=='C'||S[a]=='D'
||S[a]=='F'||S[a]=='G'||S[a]=='K'
||S[a]=='P'||S[a]=='Q'||S[a]=='R'
||S[a]=='4'||S[a]=='0'
||S[a]=='6'||S[a]=='7'||S[a]=='9'||S[a]=='E'||S[a]=='3'
||S[a]=='S'||S[a]=='2'
||S[a]=='Z'||S[a]=='5'||S[a]=='J'||S[a]=='L')
{mir=false;}
}
if(pal==false&&mir==false)
{cout<<S<<" -- is not a palindrome.";}
else if(pal==false&&mir==true)
{cout<<S<<" -- is a mirrored string.";}
else if(pal==true&&mir==false)
{cout<<S<<" -- is a regular palindrome.";}
else
{cout<<S<<" -- is a mirrored palindrome.";}

cout<<endl;
cout<<endl;
}
return 0;

}//` ''

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

Re: 401-Palindromes Why getting WA

Post by brianfry713 » Mon Feb 03, 2014 9:51 pm

Don't double post.
Check input and AC output for thousands of problems on uDebug!

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

Re: 401- Palindromes

Post by brianfry713 » Mon Feb 03, 2014 10:09 pm

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

setu basak
New poster
Posts: 4
Joined: Sun Aug 04, 2013 8:35 am

why wa in uva-401??

Post by setu basak » Mon May 26, 2014 7:14 pm

Code: Select all

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
using namespace std;
bool regular(string a)
{
	int len = a.length();
	bool flag = true;
	for (int i = 0; i < len / 2; i++)
	{
		if (a.at(i) != a.at(len - i - 1))
		{
			flag = false;
			break;
		}
	}
	return flag;
}
bool mirror(string a)
{
	char ch[35] = { '1', 'S', 'E', '*', 'Z', '*', '*', '8', '*', 'A', '*', '*', '*', '3', '*', '*', 'H', 'I', 'L', '*', 'J',
		'M', '*', 'O', '*', '*', '*', '2', 'T', 'U', 'V', 'W', 'X', 'Y', '5' };
	int len = a.length();
	if (len % 2 == 0)
		len = len / 2 - 1;
	else
		len = len / 2;
	for (int i = 0; i <= len; i++)
	{
		if (isalpha(a.at(i)))
		{
			if (ch[a.at(i) - 'A' + 9] == '*')
				return false;
			a.at(i) = ch[a.at(i) - 'A' + 9];
		}
		if (isdigit(a.at(i)))
		{
			if (ch[a.at(i) - '1'] == '*')
				return false;
			a.at(i) = ch[a.at(i) - '1'];
			
		}
	}
	return regular(a);
}
int main()
{
	string a;
	while (cin>>a)
	{
		bool reg = regular(a);
		bool mir = mirror(a);
		if (reg && mir)
		{
			cout << a;
			printf(" -- is a mirrored palindrome.\n\n");
		}
		else if (!reg && mir)
		{
			cout << a;
			printf(" -- is a mirrored string.\n\n");
		}
		else if (reg && !mir)
		{
			cout << a;
			printf(" -- is a regular palindrome.\n\n");
		}
		else if (!reg && !mir)
		{
			cout << a;
			printf(" -- is not a palindrome.\n\n");
		}
	}
}

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

Re: why wa in uva-401??

Post by brianfry713 » Wed Jun 11, 2014 8:24 pm

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

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

Re: 401-Palindromes Why getting WA

Post by blackheartadhar » Mon Jun 23, 2014 3:58 pm

Getting WA! Please help.

Code: Select all

Removed After AC!
Last edited by blackheartadhar on Thu Jun 26, 2014 3:52 pm, edited 1 time in total.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 401-Palindromes Why getting WA

Post by lbv » Mon Jun 23, 2014 9:15 pm

blackheartadhar wrote:Getting WA! Please help.
From the output specification: In addition, after each output line, you must print an empty line. There are no exceptions for the last test case.

In addition, try the cases:

Input

Code: Select all

3QE
Z55
Output

Code: Select all

3QE -- is not a palindrome.

Z55 -- is not a palindrome.


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

Re: 401-Palindromes Why getting WA

Post by blackheartadhar » Tue Jun 24, 2014 11:31 am

Now I'm getting Compile error! :(

Code: Select all

Removed After AC!
Last edited by blackheartadhar on Thu Jun 26, 2014 3:57 pm, edited 1 time in total.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 401-Palindromes Why getting WA

Post by lbv » Tue Jun 24, 2014 6:03 pm

blackheartadhar wrote:Now I'm getting Compile error! :(
I have just submitted the latest code you posted as-is, and got AC. Maybe you submitted the wrong file? Or forgot to comment the freopen lines?

lichtgestalt01
New poster
Posts: 4
Joined: Sun Jun 22, 2014 6:00 am

Re: 401-Palindromes Why getting WA

Post by lichtgestalt01 » Thu Jun 26, 2014 5:57 am

here's some input cases i tried

Input:

Code: Select all

2BBS
B2SB
BBB
BBBB
AAA
AAAA
HII
O
X
B
xX
b
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.



Post Reply

Return to “Volume 4 (400-499)”