401 palindromes WA help

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

Moderator: Board moderators

401 palindromes WA help

Postby ice_mountain_ » Mon Nov 01, 2004 4:48 pm

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[i]=b[i];
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[i];
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[i]=='B' || c[i]=='C' ||c[i]=='D' || c[i]=='F' || c[i]=='G' || c[i]=='K' ||c[i]=='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!
ice_mountain_
New poster
 
Posts: 5
Joined: Wed Sep 29, 2004 7:25 pm

Postby n00i3 » Tue Oct 04, 2005 10:09 pm

8 is a mirrored palindrome
whereas C is a regular palindrome :P
n00i3
New poster
 
Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm

Postby tmdrbs6584 » Tue Mar 14, 2006 10:54 am

palindrome...
User avatar
tmdrbs6584
Learning poster
 
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

401 WA please help!!!

Postby pushpit.saxena » Tue Feb 06, 2007 4:42 pm

my code is::

#include<string>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

bool CheckPalin(string x)
{
string y;
y.assign(x,0,x.size());
reverse(y.begin(),y.end());
if(y==x)
return true;
else
return false;
}
bool getMirror(string x,string character , string reverse1)
{
string y="";
char ch;
for(int i=0;i<x.size();i++)
if((ch=reverse1[character.find(x[i],0)])!=' ')
y+=ch;
else
return false;
reverse(y.begin(),y.end());
if(x==y)
return true;
return false;
}



int main()
{

int i;
string input;
fflush(stdin);
string character="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
string reverse1="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
while(cin>>input)
{
bool m=getMirror(input,character,reverse1);
bool p=CheckPalin(input);
if(m && p)
cout<<input<<" -- is a mirrored palindrome.\n\n";
else if(m && !p)
cout<<input<<" -- is a mirroed string.\n\n";
else if(!m && p)
cout<<input<<" -- is a regular palindrome.\n\n";
else if(!m && !p)
cout<<input<<" -- is not a palindrome.\n\n";


fflush(stdin);
input.erase(input.begin(),input.end());
}

return 0;
}

please help me out....
I m getting WA...
Happy Coding!!!
Pushpit Saxena
B-Tech@IIIT-A
pushpit.saxena
New poster
 
Posts: 4
Joined: Mon Jan 22, 2007 10:05 pm
Location: Allahabad

plzzzz help!!

Postby pushpit.saxena » Mon Feb 12, 2007 5:14 pm

my code is in the above post......
plzzzzzz help me out I m getting WA!!
Happy Coding!!!
Pushpit Saxena
B-Tech@IIIT-A
pushpit.saxena
New poster
 
Posts: 4
Joined: Mon Jan 22, 2007 10:05 pm
Location: Allahabad

401(Palindrome)WA

Postby ishtiaq ahmed » Fri Aug 03, 2007 6:12 am

Can anybody inform me where is my error? Waiting for your reply. Here is my code...
Code: Select all
the code is removed after ac.
Thanks to JAN bhia.
Last edited by ishtiaq ahmed on Sun Feb 17, 2008 7:20 pm, edited 1 time in total.
No venture no gain

with best regards
------------------------
ishtiaq ahmed
ishtiaq ahmed
Learning poster
 
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

Postby Jan » Fri Aug 03, 2007 3:19 pm

Try the cases.

Input:
Code: Select all
H22H
EVE
MJJM
J
YJ33JY

Output:
Code: Select all
H22H -- is a regular palindrome.

EVE -- is a regular palindrome.

MJJM -- is a regular palindrome.

J -- is a regular palindrome.

YJ33JY -- is a regular palindrome.

Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

getting WA in #401--can anyone help?

Postby jesun » Sun Jan 13, 2008 3:41 pm

I have tried all test cases given in the forum and got the desired results.
But I still get WA .Can anyone do the favor to take a look at my code &
figure out the bug?thanks in advance.

my code:
Code: Select all
REMOVED AFTER AC.


[Edited by : Jan] Use code tags.
Code: Select all
Last edited by jesun on Tue Jan 15, 2008 9:12 am, edited 1 time in total.
jesun
New poster
 
Posts: 10
Joined: Tue Jan 01, 2008 10:55 pm

Postby Jan » Sun Jan 13, 2008 10:00 pm

Try the cases.

Input:
Code: Select all
ISSEJML11JML322I
SV2OSV2
8SZSJYYL2528

Output:
Code: Select all
ISSEJML11JML322I -- is a mirrored string.

SV2OSV2 -- is a mirrored string.

8SZSJYYL2528 -- is a mirrored string.

Hope these help.
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

THANKS!!!

Postby jesun » Tue Jan 15, 2008 9:10 am

THANKS JAN bhai for your i/p set.It's really helpful!!I have missed {'s','2'} matching set.that's why I was getting WA.Thanks again for your help to get AC.
AND oh yes! I shall try to remember to use code tags if necessary.
jesun
New poster
 
Posts: 10
Joined: Tue Jan 01, 2008 10:55 pm

Re: 401 palindromes WA help

Postby Mohiuddin » Tue Apr 29, 2008 7:04 pm

i m getting w a. i can't understand what's the mistake? Plzz help..

Code: Select all
#include<stdio.h>
#include<string.h>
int main (void)
{
   int i,j,k,p,q;

   char ch[21];

   char ch1[21]={'A','E','H','I','J','L','M','O','S','T','U','V','W','X','Y','Z','1','2','3','5','8'};

   char ch2[21]={'A','3','H','I','L','J','M','O','2','T','U','V','W','X','Y','5','1','S','E','Z','8'};

   while(scanf("%s",ch)!=EOF)
   {
      p=0;

      q=0;

      for (i=0,j=strlen(ch)-1;i<=j/2;i++,j--)
      {
         if (ch[i]!=ch[j])
         {
            p=1;
            break;

         }
      }

      for (i=0,j=strlen(ch)-1;i<=j/2;i++,j--)
      {
         for(k=0;k<21;k++)
         {
            if (ch[i]==ch1[k])
            {
               break;

            }
         }
         
         if(k==21||ch[j]!=ch2[k])
         {
            q=1;
            break;
         }
      }

      if (p&&q)
      {
         printf ("%s -- is not a palindrome\n\n",ch);

      }
      else if(p==0&&q)
      {
         printf ("%s -- is a regular palindrome\n\n",ch);
      }
      else if (p&&q==0)
      {
         printf ("%s -- is a mirrored string\n\n",ch);
      }
      else if(p==0&&q==0)
      {
         printf ("%s -- is a mirrored palindrome\n\n",ch);
      }

   }
   return 0;
}
Mohiuddin
New poster
 
Posts: 6
Joined: Fri Apr 25, 2008 12:09 pm

Re: 401 palindromes WA help

Postby Jan » Wed Apr 30, 2008 3:25 pm

Your code doesn't even pass the samples. (Check carefully, a single 'full stop' can be dangerous)
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Re: 401 palindromes WA help

Postby samin » Fri Jul 18, 2008 9:57 pm

hello plz can any one help????????


Thanx vaiya
Last edited by samin on Fri Oct 24, 2008 9:23 pm, edited 1 time in total.
samin
New poster
 
Posts: 5
Joined: Fri Jul 18, 2008 9:29 pm

Re: 401 palindromes WA help

Postby lnr » Fri Oct 17, 2008 7:39 pm

To samin.
Problem says:
In addition, after each output line, you must print an empty line.

May be you are not printing the blank line.
See the output format in this post above and in the problem.
Compare the format with yours.
Last edited by lnr on Fri Oct 17, 2008 8:45 pm, edited 1 time in total.
User avatar
lnr
Experienced poster
 
Posts: 137
Joined: Sat Jun 30, 2007 2:52 pm
Location: (DU,CSE)Dhaka,Bangladesh

Re: 401 palindromes WA help

Postby lnr » Fri Oct 17, 2008 8:01 pm

To pushpit.saxena

Try these.
input:
Code: Select all
ISSEJML11JML322I
SV2OSV2
8SZSJYYL2528

output:
Code: Select all
ISSEJML11JML322I -- is a mirrored string.

SV2OSV2 -- is a mirrored string.

8SZSJYYL2528 -- is a mirrored string.
User avatar
lnr
Experienced poster
 
Posts: 137
Joined: Sat Jun 30, 2007 2:52 pm
Location: (DU,CSE)Dhaka,Bangladesh

Next

Return to Volume IV

Who is online

Users browsing this forum: No registered users and 1 guest