943,403 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 9190
  • C RSS
Dec 6th, 2004
0

To form a palindrome of a given string

Expand 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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
varunrathi is offline Offline
41 posts
since Aug 2004
Dec 6th, 2004
0

Re: To form a palindrome of a given string

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 6th, 2004
0

Re: To form a palindrome of a given string

please help to initiate me. i don`t want the full work to be done
Reputation Points: 10
Solved Threads: 1
Light Poster
varunrathi is offline Offline
41 posts
since Aug 2004
Dec 6th, 2004
0

Re: To form a palindrome of a given string

start by yourself then come back with specific questions.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 6th, 2004
0

Re: To form a palindrome of a given string

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
nvanevski is offline Offline
12 posts
since Dec 2004
Dec 6th, 2004
0

Re: To form a palindrome of a given string

Hey! NVANEVSKI,
Thanks a lot. Your suggestion made the program so easy that i have just finished doing it.
Reputation Points: 10
Solved Threads: 1
Light Poster
varunrathi is offline Offline
41 posts
since Aug 2004
Aug 3rd, 2009
0

Re: To form a palindrome of a given string

Click to Expand / Collapse  Quote originally posted by varunrathi ...
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();
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jagsss16 is offline Offline
4 posts
since Aug 2009
Aug 3rd, 2009
0

Re: To form a palindrome of a given string

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.
Reputation Points: 651
Solved Threads: 35
Posting Whiz in Training
yellowSnow is offline Offline
201 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: help me in pattern
Next Thread in C Forum Timeline: gotxy function REPLY





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC