To form a palindrome of a given string

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2004
Posts: 41
Reputation: varunrathi is an unknown quantity at this point 
Solved Threads: 1
varunrathi's Avatar
varunrathi varunrathi is offline Offline
Light Poster

To form a palindrome of a given string

 
0
  #1
Dec 6th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: To form a palindrome of a given string

 
0
  #2
Dec 6th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 41
Reputation: varunrathi is an unknown quantity at this point 
Solved Threads: 1
varunrathi's Avatar
varunrathi varunrathi is offline Offline
Light Poster

Re: To form a palindrome of a given string

 
0
  #3
Dec 6th, 2004
please help to initiate me. i don`t want the full work to be done
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: To form a palindrome of a given string

 
0
  #4
Dec 6th, 2004
start by yourself then come back with specific questions.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 12
Reputation: nvanevski is an unknown quantity at this point 
Solved Threads: 1
nvanevski nvanevski is offline Offline
Newbie Poster

Re: To form a palindrome of a given string

 
0
  #5
Dec 6th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 41
Reputation: varunrathi is an unknown quantity at this point 
Solved Threads: 1
varunrathi's Avatar
varunrathi varunrathi is offline Offline
Light Poster

Re: To form a palindrome of a given string

 
0
  #6
Dec 6th, 2004
Hey! NVANEVSKI,
Thanks a lot. Your suggestion made the program so easy that i have just finished doing it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 4
Reputation: jagsss16 is an unknown quantity at this point 
Solved Threads: 0
jagsss16 jagsss16 is offline Offline
Newbie Poster

Re: To form a palindrome of a given string

 
0
  #7
Aug 3rd, 2009
Originally Posted by varunrathi View Post
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<stdio.h>
#include<conio.h>
#include<string.h>
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<l-1;i++)
{
printf("%c",pal[i]);
}
for(i=l-2;i>=0;i--)
{
printf("%c",pal[i]);
}
getch();
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 201
Reputation: yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold 
Solved Threads: 35
yellowSnow's Avatar
yellowSnow yellowSnow is offline Offline
Posting Whiz in Training

Re: To form a palindrome of a given string

 
0
  #8
Aug 3rd, 2009
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.
Manic twiddler of bits
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC