954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

To form a palindrome of a given string

HI EVERYONE,
I HAVE GOT A VERY INTERESTING PROBLEM THIS TIME. U HAVE TO FORM A PALINDROME OF AN ENTERED STRING. IT`S NOT THE UASUAL STUFF OF CHECKING WHETHER AN ENTERED STRING IS A PALINDROME OR NOT.
IN THIS PROGRAM, SAY IF THE GIVEN STRING IS:
"A3BCA"
THEN THE PROGRAM SHOULD FORM THE SHORTEST PALINDROME POSSIBLE BY INSERTING "CB3" AT THE SECOND LAST POSITION;
i.e; THE OUTPUT SHOULD BE
"A3BCCB3A"
OR THE OUTPUT CAN ALSO BE
"A3CBC3A"
OR

OR IF THE INPUT IS "AAMDM"
THEN THE SOLUTION IS "AAMDMAA" AND NOT "MDMAAMDM" B`COS WE HAVE TO FIND THE SHORTEST POSSIBLE PALINDROME.

SO, PLZ CAN ANY 1 HELP ME TO BEGIN IN THE RIGHT DIRECTION.

varunrathi
Light Poster
41 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

ah, it's that time of year again.
About right, few weeks before the Christmas vacation...

P.S. posting in all caps is unlikely to get you more help. In fact it's extremely annoying and I won't read any post written that way.
P.P.S. read the posting guidelines. We're not here to do your homework for you.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

please help to initiate me. i don`t want the full work to be done

varunrathi
Light Poster
41 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

start by yourself then come back with specific questions.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Ok, I'll just give you a hint, try to do the program by yourself. Start with matching the characters on the opposite end of the string. On the first mismatch, get the rest of the string, create the reverse string from it and insert it into the right position.

When you do this kind of programs, try to document your thinking with code-like (pseudo-code) sentences. Helps a lot with actual coding.

nvanevski
Newbie Poster
12 posts since Dec 2004
Reputation Points: 10
Solved Threads: 1
 

Hey! NVANEVSKI,
Thanks a lot. Your suggestion made the program so easy that i have just finished doing it.

varunrathi
Light Poster
41 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

HI EVERYONE, I HAVE GOT A VERY INTERESTING PROBLEM THIS TIME. U HAVE TO FORM A PALINDROME OF AN ENTERED STRING. IT`S NOT THE UASUAL STUFF OF CHECKING WHETHER AN ENTERED STRING IS A PALINDROME OR NOT. IN THIS PROGRAM, SAY IF THE GIVEN STRING IS: "A3BCA" THEN THE PROGRAM SHOULD FORM THE SHORTEST PALINDROME POSSIBLE BY INSERTING "CB3" AT THE SECOND LAST POSITION; i.e; THE OUTPUT SHOULD BE "A3BCCB3A" OR THE OUTPUT CAN ALSO BE "A3CBC3A" OR OR IF THE INPUT IS "AAMDM" THEN THE SOLUTION IS "AAMDMAA" AND NOT "MDMAAMDM" B`COS WE HAVE TO FIND THE SHORTEST POSSIBLE PALINDROME.

SO, PLZ CAN ANY 1 HELP ME TO BEGIN IN THE RIGHT DIRECTION.


#include
#include
#include
int i,l=0,n,p;
char pal[10];
void main()
{
clrscr();
printf("Enter string:");
scanf("%s",pal);
l=strlen(pal);
for(i=0;i=0;i--)
{
printf("%c",pal[i]);
}
getch();
}

jagsss16
Newbie Poster
4 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This post is over four and half years old and it was SOLVED. Why are you reviving old threads.

And there's that blasted void main again.

yellowSnow
Posting Whiz in Training
203 posts since Jul 2009
Reputation Points: 651
Solved Threads: 35
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You