Page 8 of 14
Posted: Tue Nov 07, 2006 6:05 pm
by Salehwar
Oh well, I guess I'll never be able to solve it
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.
Posted: Tue Nov 07, 2006 8:53 pm
by ALEXANDRIA_2
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..

Posted: Tue Nov 07, 2006 8:59 pm
by Salehwar
Oh my god!!!!! I feel so stupid! that was the mistake! I got AC
Thank you alot, and god bless you
401-WA plzzzzzz help!!!
Posted: Mon Feb 05, 2007 11:55 pm
by pushpit.saxena
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,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....
Posted: Tue Feb 06, 2007 8:07 am
by helloneo
Try to search first.. and don't open a new thread if there is one already.
401 WA please help!!!
Posted: Tue Feb 06, 2007 4:42 pm
by pushpit.saxena
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,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...
plzzzz help!!
Posted: Mon Feb 12, 2007 5:14 pm
by pushpit.saxena
my code is in the above post......
plzzzzzz help me out I m getting WA!!
401(Palindrome)WA
Posted: Fri Aug 03, 2007 6:12 am
by ishtiaq ahmed
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.
Posted: Fri Aug 03, 2007 3:19 pm
by Jan
Try the cases.
Input:
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.
getting WA in #401--can anyone help?
Posted: Sun Jan 13, 2008 3:41 pm
by jesun
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:
[Edited by : Jan] Use code tags.
Posted: Sun Jan 13, 2008 10:00 pm
by Jan
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.
THANKS!!!
Posted: Tue Jan 15, 2008 9:10 am
by jesun
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.
Re: 401 palindromes WA help
Posted: Tue Apr 29, 2008 7:04 pm
by Mohiuddin
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;
}
Re: 401 palindromes WA help
Posted: Wed Apr 30, 2008 3:25 pm
by Jan
Your code doesn't even pass the samples. (Check carefully, a single 'full stop' can be dangerous)
Palindromes 401 WA
Posted: Sun Jul 13, 2008 7:30 pm
by KaDeG
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,
KaDeG