## 401 - Palindromes

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

Oh well, I guess I'll never be able to solve it
Code: Select all
`Removed after AC   `

I added the new function MirroredChar2 to check if the character is a valid character since I haven't checked that, but still WA!

Thank you.
Last edited by Salehwar on Tue Nov 07, 2006 9:04 pm, edited 1 time in total.
Salehwar
New poster

Posts: 9
Joined: Mon Oct 09, 2006 3:48 pm

Hi Salehwar...
don't give up...
u only need to fix ur output statement

Code: Select all
`cout<<str<<" -- is a regular plaindrome.\n"<<endl;`

to
Code: Select all
`cout<<str<<" -- is a regular palindrome.\n"<<endl;`

and don't forget to remove ur code after get AC..
Impossible is nothing
ALEXANDRIA_2
New poster

Posts: 10
Joined: Tue Nov 07, 2006 2:03 pm
Location: Jakarta

Oh my god!!!!! I feel so stupid! that was the mistake! I got AC

Thank you alot, and god bless you
Salehwar
New poster

Posts: 9
Joined: Mon Oct 09, 2006 3:48 pm

### 401-WA plzzzzzz help!!!

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

can anyone find out where i m wrong....
Happy Coding!!!
Pushpit Saxena
B-Tech@IIIT-A
pushpit.saxena
New poster

Posts: 4
Joined: Mon Jan 22, 2007 10:05 pm

Try to search first.. and don't open a new thread if there is one already.
helloneo
Guru

Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

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

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

### plzzzz help!!

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

### 401(Palindrome)WA

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

Try the cases.

Input:
Code: Select all
`H22HEVEMJJMJYJ33JY`

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

### getting WA in #401--can anyone help?

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

Try the cases.

Input:
Code: Select all
`ISSEJML11JML322ISV2OSV28SZSJYYL2528`

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

### THANKS!!!

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

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

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

### Palindromes 401 WA

Hello,
I tried solving Palindromes(401) problem. But keep getting Wrong Answer
although I searched the forums for test cases and in all of them my code worked correct.
Here is my code:
Code: Select all
`#include <stdio.h>#include <string.h>/* check if a given string is palindrome */int isPalindrome(char *s){    int i, j;    for (i = 0, j = strlen(s) - 1; i <= j; ++i, --j)     {        if (s[i] != s[j])            return 0;    }    return 1;}/* check if a given string is mirrored */int isMirror(char *s){    int i, j, c, k;    char *nonReversed = "BCDFGKNPQR04679"; /* not valid characters.(unreversable characters) */    /* reversed characters with their reverse */    char mirror[21][2] = {{'A', 'A'}, {'E', '3'}, {'H', 'H'}, {'I', 'I'}, {'J', 'L'}, {'L', 'J'},                            {'M', 'M'}, {'O', 'O'}, {'S', '2'}, {'T', 'T'}, {'U', 'U'}, {'V', 'V'},                                {'W', 'W'}, {'X', 'X'}, {'Y', 'Y'}, {'Z', '5'}, {'1', '1'},                                    {'2', 'S'}, {'3', 'E'}, {'5', 'Z'}, {'8', '8'}};    /* if given string has a character that cannot be reversed      * the string is sure not mirrored */    for (i = 0; s[i] != '\0'; ++i)      {        c = s[i];        for (j = 0; nonReversed[j] != '\0'; ++j)        {            if (c == nonReversed[j])    {                return 0;            }        }    }    for (i = 0, j = strlen(s) - 1; i <= j; ++i, --j)    {        for (k = 0; k < 21; ++k)        {            if (mirror[k][0] == s[i])   {                if (s[j] != mirror[k][1])       {                    return 0;                }                break;            }        }    }    return 1;}int main(){    char name[30];    while (scanf("%s", name) != EOF)    {        if (isPalindrome(name)) {            if (isMirror(name)) {                printf("%s -- is mirrored palindrome.\n");            }            else        {                printf("%s -- is regular palindrome.\n");            }        }        else    {            if (isMirror(name)) {                printf("%s -- is a mirrored string.\n");            }            else        {                printf("%s -- is not a palindrome.\n");            }        }        printf("\n");    }    return 0;}`

Any test-cases or code problems would be very help full.
Thanks,
/*No Comment*/

New poster

Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

PreviousNext

### Who is online

Users browsing this forum: No registered users and 0 guests