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
mhayter1
New poster
Posts: 15
Joined: Wed Jul 26, 2006 10:00 am

Post by mhayter1 »

You need to change this portion of code.

Code: Select all

if(lookup[str1[i]]=='\0') 
       { 
           mirror[i]=str1[i]; 
           return 0;
       } 

mhayter1
New poster
Posts: 15
Joined: Wed Jul 26, 2006 10:00 am

Post by mhayter1 »

Gee!!Thanks for your reply!

I got AC!!

mhayter1
New poster
Posts: 15
Joined: Wed Jul 26, 2006 10:00 am

Post by mhayter1 »

Please remove your code from the forum.

mhayter1
New poster
Posts: 15
Joined: Wed Jul 26, 2006 10:00 am

Post by mhayter1 »

I would but I don't know how. Could someone tell me?

belial
New poster
Posts: 1
Joined: Fri Aug 11, 2006 9:44 am

Post by belial »

grrr... with this i got WA:

Code: Select all

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

#define NOTHING      0
#define PALYNDROME   2
#define MIRRORED     4
#define BOTH         6

void righttoleft(char *thestring)
{
	int n = strlen(thestring);
	char *temp = strdup(thestring);

	while (n != 0)
		*(thestring++) = temp[--n];
}

void trytomirror(char *thestring)
{
	while (*thestring != 0) {
		switch (*thestring) {
			case 'E':
				*thestring = '3';
				break;
			case 'S':
				*thestring = '2';
				break;
			case 'Z':
				*thestring = '5';
				break;
			case '2':
				*thestring = 'S';
				break;
			case '3':
				*thestring = 'E';
				break;
			case '5':
				*thestring = 'Z';
				break;
			case 'B' : case 'C' : case 'D' : case 'F' : case 'K' :
			case 'P' : case 'Q' : case 'R' : case '4' : case '6' :
			case '7' : case '9' : case '0' :
				/* invalid characters for mirrored strings */
				*thestring = '?';
				break;
			default:
				break;
		}
		++thestring;
	}
}

int main()
{
	char *copy, stringinput[25];
	int flags;

	while (gets(stringinput)) {
		flags = NOTHING;
		copy = strdup(stringinput);
		righttoleft(copy);
		if (!strcmp(copy, stringinput))
			flags = PALYNDROME;

		trytomirror(copy);
		if (!strcmp(copy, stringinput))
			flags |= MIRRORED;

		printf("%s -- %s\n\n", stringinput,
		                       (flags == BOTH) ? "is a mirrored palindrome." :
		                        (flags == MIRRORED) ? "is a mirrored string." :
		                        (flags == PALYNDROME) ? "is a regular palindrome." :
		                        "is not a palindrome.");
	}
	return 0;
}
i'm really stuck... :-?

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

Problem 401 WA!

Post by Salehwar »

Hello

I read all posts about problem 401 WA and still I couldn't find my error. I keep getting WA and I really don't like to ask any help for solving these problems because I like programming and I like to be good on it. I have been stock on 401 for awhile. I'll really appreciate if anyone can help me to find the mistake on the following code.. I will delete it as soon as I get the answer.

Code: Select all

Deleted after AC
 	

Thank you alot
Last edited by Salehwar on Tue Nov 07, 2006 8:59 pm, edited 1 time in total.

dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

401--PLZ HELP!!!!!!!!!!!!

Post by dust_cover »

Hey me too have read all the posts but getting WA. This program runs for every test cases given previously in the posts.
But I think I am making any mistakes about "O"(char) & "0"(letter).
I considered 2 of them same i mean I changed any "0" (zero) to "O" while taking input.

Can someone tell me if I am right?

Code: Select all


Removed after ACC


--thnx in advance! :D
Last edited by dust_cover on Wed Nov 01, 2006 10:12 am, edited 1 time in total.
i wanna give it a try....

dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

I got ACC

Post by dust_cover »

hi ,
I dont think so we need to handle 0 or O.
After removing the part of 0 & O I got ACC. moreover I forgot to print one extra line after each output set.

But what does that mean

Code: Select all

Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.
--thanx in advance!
i wanna give it a try....

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

Post by Salehwar »

Yeah I forgot to deal with 0 and O

I tried to add the following 2, but still WA:

Code: Select all

case'O': return 'O';

Code: Select all

case'O': case '0': return 'O';
What exactly you did? did you ignore 0 on input or what?

Thanks

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

very confused bout 401....

Post by ALEXANDRIA_2 »

Hi all, can anybody tell me what's wrong with my code..
I still gettin WA all the time...

Code: Select all

Removed after get ACC
Thanks..
Last edited by ALEXANDRIA_2 on Tue Nov 07, 2006 3:26 pm, edited 1 time in total.
Impossible is nothing

rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

Read the problem carefully.
In addition, after each output line, you must print an empty line.

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

Post by Salehwar »

I added an empty line, but still WA

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

Post by ALEXANDRIA_2 »

to Salehwar
u can try :

Code: Select all

input:
8
C
ATOYOTA
AT0Y0TA
ATOY0TA

Code: Select all

output
8 -- is a mirrored palindrome.

C -- is regular palindrome.

ATOYOTA -- is a mirrored palindrome.

AT0Y0TA -- is a regular palindrome.

ATOY0TA -- is not a palindrome.

Hope u get AC soon...
Impossible is nothing

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

Post by Salehwar »

Code: Select all

output 
8 -- is a mirrored palindrome. 

C -- is regular palindrome. 

ATOYOTA -- is a mirrored palindrome. 

AT0Y0TA -- is a regular palindrome. 

ATOY0TA -- is not a palindrome. 
Wht is second AT0Y0TA is a regular palindrome? is itn't it suppose to be mirrored? since its regular palindrome and mirrored string.

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

Post by ALEXANDRIA_2 »

Code: Select all

Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.
I thought a valid character means that it have a reverse character,
the second AT0Y0TA is formed by two 0(zero), since zero doesn't have the reverse character so it wasn't a mirrored.
Impossible is nothing

Post Reply

Return to “Volume 4 (400-499)”