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

Post Reply
Hanselmin
New poster
Posts: 2
Joined: Fri Jan 30, 2004 7:52 am

401 - WA

Post by Hanselmin »

i've try all test input i've seen...and all ouput are all correct

but it still got WA

plz help me~~

thx :P

Code: Select all

[cpp]

CUT

i got AC

[/cpp]

ice_mountain_
New poster
Posts: 5
Joined: Wed Sep 29, 2004 7:25 pm

401 palindromes WA help

Post by ice_mountain_ »

hi everyone, i am completely out of ideas why i'm getting WA, so pls help!

this is my solution (JAVA) to problem 401 palindromes:

the comments are not included when i submit, and the classname is changed to Main also.

[java]
class palindrome{
static char[] input=null;
static boolean isPalindrome=false;
static boolean isMirroredString=false;
static void main(){
int a;
char[] b=new char[19];
int count=0;
boolean EOFreached=false;
while(EOFreached==false){
try{
while((a=System.in.read())!=(int)'\n'){
if(a==-1){ //is this the right code for detecting EOF?
EOFreached=true;
break;
}
b[count]=(char)a;
count++;
}
}catch(Exception e){}
char[] c=new char[count];
for(int i=0; i<count; i++)
c=b;
checkPalindrome(c);
checkMirroredString(c);
String s=new String(c);
if(isPalindrome==true){
if(isMirroredString==true)
System.out.println(s+" -- is a mirrored palindrome.");
else
System.out.println(s+" -- is a regular palindrome.");
}
else if(isPalindrome==false){
if(isMirroredString==true)
System.out.println(s+" -- is a mirrored string.");
else
System.out.println(s+" -- is not a palindrome.");
}
isPalindrome=false;
isMirroredString=false;
count=0;
}
}
static void checkPalindrome(char[] p){ //simply creates a reverse of the string see if its the same as b4
char[] r=new char[p.length];
for(int i=0; i<p.length; i++)
r[p.length-(i+1)]=p;
if(equals(r,p))
isPalindrome=true;
}
static void checkMirroredString(char[] c){ //chages chars to their reverses and then creates a reverse of the whole thing to compare to input
char[] r=new char[c.length];
for(int i=0;i<c.length;i++){
if(c=='B' || c=='C' ||c=='D' || c=='F' || c=='G' || c=='K' ||c=='N' || c[i]=='P' || c[i]=='Q'
|| c[i]=='R' || c[i]=='4' || c[i]=='6' || c[i]=='7' || c[i]=='9'){
isMirroredString=false;
break;
}
else if(c[i]!='A'&&c[i]!='H'&&c[i]!='I'&&c[i]!='M'&&c[i]!='O'&&c[i]!='T'&&c[i]!='U'&&c[i]!='V'&&c[i]!='W'&&c[i]!='X'
&&c[i]!='Y'&&c[i]!='1'&&c[i]!='8'){
if(c[i]=='E')
r[c.length-i-1]='3';
else if(c[i]=='L')
r[c.length-i-1]='J';
else if(c[i]=='S')
r[c.length-i-1]='2';
else if(c[i]=='Z')
r[c.length-i-1]='5';
else if(c[i]=='2')
r[c.length-i-1]='S';
else if(c[i]=='3')
r[c.length-i-1]='E';
else if(c[i]=='5')
r[c.length-i-1]='Z';
}
else
r[c.length-(i+1)]=c[i];
}
if(equals(r,c))
isMirroredString=true;
}
static boolean equals(char[] a, char[] b){
for(int i=0;i<a.length;i++){
if(a[i]!=b[i]){
return false;
}
else
continue;
}
return true;
}
}
[/java]

thx!

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

401 - Palindromes - HELP IN JAVA

Post by Jemerson »

Code: Select all

	static char[] word;
	static Hashtable mirrors;
	
	public static void main(String args[]) {
	    boolean palindrome;
		boolean mirror;
	    mirrors = new Hashtable();
		String entrada = readLn(100);
		mirrors.put("A","A"); mirrors.put("E","3"); mirrors.put("H","H");
		mirrors.put("I","I"); mirrors.put("J","L");	mirrors.put("M","M");
		mirrors.put("O","O"); mirrors.put("S","2");	mirrors.put("T","T");
		mirrors.put("U","U"); mirrors.put("V","V"); mirrors.put("X","X");
		mirrors.put("W","W"); mirrors.put("Y","Y"); mirrors.put("Z","5");
		mirrors.put("1","1"); mirrors.put("2","S");	mirrors.put("3","E");
		mirrors.put("5","Z"); mirrors.put("8","8");
		
		while (entrada != null && !entrada.equals("")) {
			palindrome = verifyPalindrome(entrada);
			mirror = verifyMirrored(entrada);
			if (palindrome && mirror) 
				System.out.println(entrada + " -- is a mirrored palindrome.\n");
			else if (palindrome) 
				System.out.println(entrada + " -- is a regular palindrome.\n");
			else if (mirror) 
				System.out.println(entrada + " -- is a mirrored string.\n");
			else System.out.println(entrada + " -- is a not a palindrome.\n");
			entrada = readLn(255);
		}
	}
	
	static boolean verifyMirrored(String input) {
		word = input.toCharArray(); 
		int last = word.length -1;
		if (last == 0) // ONLY ONE CHAR;
		    return false;
		for (int i = 0; i <= last; i++) {
		    String s1 = String.valueOf(word[last]);
		    String s2 = String.valueOf(word[i]);
		    String s3 = (String)mirrors.get(s2);
			if (!s1.equals(s3)) 
				return false;
			last--;
		}
		return true;
	}

	static boolean verifyPalindrome(String entrada) {
		word = entrada.toCharArray();
		int last = word.length - 1;
		for (int i = 0; i <= last / 2; i++) {
		    if (word[i] != word[last - i]) 
		        return false;
		}
		return true;
	}
Im getting WA's and dont understand why, can anyone help me?

Thanx in advance

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

Post by Jemerson »

it was missing the L, J rule..
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Post by tan_Yui »

I fixed the output data posted on this thread.
I hope this help all of men who got WA.

Input :
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
MAIAM
123ESI
123ES1
DEO3D
9339
A
B
E
M
1
3
2
4
Output should be :
NOTAPALINDROME -- is not a palindrome.

ISAPALINILAPASI -- is a regular palindrome.

2A3MEAS -- is a mirrored string.

ATOYOTA -- is a mirrored palindrome.

MAIAM -- is a mirrored palindrome.

123ESI -- is not a palindrome.

123ES1 -- is a mirrored string.

DEO3D -- is not a palindrome.

9339 -- is a regular palindrome.

A -- is a mirrored palindrome.

B -- is a regular palindrome.

E -- is a regular palindrome.

M -- is a mirrored palindrome.

1 -- is a mirrored palindrome.

3 -- is a regular palindrome.

2 -- is a regular palindrome.

4 -- is a regular palindrome.
Best regards.
Last edited by tan_Yui on Wed Oct 05, 2005 7:05 am, edited 1 time in total.

n00i3
New poster
Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm
Contact:

Post by n00i3 »

yeah BOmb... didnt have the checks in for the single characters :P

n00i3
New poster
Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm
Contact:

Post by n00i3 »

8 is a mirrored palindrome
whereas C is a regular palindrome :P

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Post by tan_Yui »

n00i3 wrote:yeah BOmb... didnt have the checks in for the single characters :P
Yes, we must take care of the input consisting of the single character. :D

mohsincsedu
Learning poster
Posts: 63
Joined: Tue Sep 20, 2005 12:31 am
Location: Dhaka
Contact:

401_WA_Boring.....

Post by mohsincsedu »

Hi.............
I got WA.
Plz give me same input..

Code: Select all

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




int Palind(char *string)
{
	int len,i;
	len = strlen(string)-1;

	for(i = 0;i<=len/2;i++)
	{
		if(string[i]!=string[len-i])
			return 0;
	}
	return 1;
}

int Mirror(char *string)
{
	char Mir[300];
	Mir['A'] = 'A'; Mir['E'] = '3'; Mir['H'] = 'H'; Mir['I'] = 'I'; Mir['J'] = 'L';
	Mir['M'] = 'M'; Mir['O'] = 'O'; Mir['S'] = '2'; Mir['T'] = 'T'; Mir['U'] = 'U'; Mir['V'] = 'V'; Mir['W'] = 'W'; Mir['X'] = 'X';
	Mir['Y'] = 'Y'; Mir['Z'] = '5'; Mir['1'] = '1'; Mir['2'] = 'S'; Mir['3'] = 'E'; Mir['5'] = 'Z'; Mir['8'] = '8';
	int len,i;
	len = strlen(string)-1;
	for(i = 0; i<=len/2;i++)
	{
		if(string[i]!=Mir[string[len-i]])
			return 0;
	}
	return 1;
}

void main()
{
	char input[30];
	int m,p;
	while(gets(input)!=NULL)
	{
		p = Palind(input);
		m = Mirror(input);
		if(!p)
		{
			if(!m)
				printf("%s -- is not a palindrome.\n\n",input);
			else
				printf("%s -- is a mirrored string.\n\n",input);
		}
		else
		{
			if(!m)
				printf("%s -- is a regular palindrome.\n\n",input);
			else
				printf("%s -- is a mirrored palindrome.\n\n",input);
		}

	}
}




//Plz help meeeee............[/b]

mohsincsedu
Learning poster
Posts: 63
Joined: Tue Sep 20, 2005 12:31 am
Location: Dhaka
Contact:

ACC

Post by mohsincsedu »

I got ACC.
my code has a simple mistake.
Don't try to find my bug in above code.

yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

why PE with 401? judge mad , plz help anybody

Post by yogeshgo05 »

i don't na why pe for this code,already 8 submission for this problem
i m frustrated......

Code: Select all

I GOT IT AC .DELETED
Last edited by yogeshgo05 on Thu Feb 16, 2006 3:41 pm, edited 1 time in total.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Did you see this line in the output description?
In addition, after each output line, you must print an empty line
You did not do that in your code.

Now, remove this code after you get AC.

yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

Post by yogeshgo05 »

hi thanks,

this is kind of problem beginnners like me face out, any way thanks man..

Lotendil
New poster
Posts: 3
Joined: Thu Feb 16, 2006 1:12 am

401 WA Palindromes

Post by Lotendil »

Edited: AC now
Last edited by Lotendil on Sat Feb 25, 2006 2:41 pm, edited 1 time in total.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

On first glance you miss "case 'S' : return '2'; break;".
Did you realy try all test in the 10+ topics on this problem before starting a new one?
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.

Post Reply

Return to “Volume 4 (400-499)”