Page 5 of 14

401 - WA

Posted: Fri Jul 09, 2004 3:19 am
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]

401 palindromes WA help

Posted: Mon Nov 01, 2004 4:48 pm
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!

401 - Palindromes - HELP IN JAVA

Posted: Mon May 09, 2005 9:11 pm
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

Posted: Sat Jun 11, 2005 4:13 am
by Jemerson
it was missing the L, J rule..

Posted: Tue Oct 04, 2005 9:43 am
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.

Posted: Tue Oct 04, 2005 9:35 pm
by n00i3
yeah BOmb... didnt have the checks in for the single characters :P

Posted: Tue Oct 04, 2005 10:09 pm
by n00i3
8 is a mirrored palindrome
whereas C is a regular palindrome :P

Posted: Wed Oct 05, 2005 7:21 am
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

401_WA_Boring.....

Posted: Wed Oct 05, 2005 10:33 pm
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]

ACC

Posted: Sun Oct 23, 2005 10:08 pm
by mohsincsedu
I got ACC.
my code has a simple mistake.
Don't try to find my bug in above code.

why PE with 401? judge mad , plz help anybody

Posted: Thu Feb 16, 2006 9:50 am
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

Posted: Thu Feb 16, 2006 11:29 am
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.

Posted: Thu Feb 16, 2006 3:35 pm
by yogeshgo05
hi thanks,

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

401 WA Palindromes

Posted: Sat Feb 25, 2006 2:16 pm
by Lotendil
Edited: AC now

Posted: Sat Feb 25, 2006 2:34 pm
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?