QUOTE(binnu @ 31 Mar, 2008 - 10:36 PM)

QUOTE(ladiesman @ 31 Mar, 2008 - 09:39 PM)

i need help with wrtiting a palindrome program but i want to know how these palindrome works. alsowhat all does the code entail dont write it for me just list like for example "capital or small words". thank you.
for example 131 is pallindrome
suppose for the asked value of n,131 is entered
intially u have to assign the n value into another variable say 'c',bcoz after completion of loop the value of n will be changed.by doin this a holds the value of n.And also assign zero to 'b'(b=0;)
first u have 2 check whether the given number is = 0 or not if not (while(n!=0), then enter the loop.
{
(1)then find remainder of the number with 10(a=n%10)it will extract the last digit in the number.i.e '1' which is stored in a.
(2)b=(b*10)+a;(b is initialized with '0')
here the value of is,b=(0*10)+1=1
(3)now find the modulus value of the number n i.e 131
n=n/10;
it will gives u the value 13 and stored in n itself.
}the loop is repeated second time ,then the digit 3 will be extracted from the number 13,and the value 'b' becomes (b=(1*10)+3))=13,again the modulus of n i.e 13 is 1.the value of n becomes 1.it enters the loop again
a value becomes 1.b value becomes(b=(13*10)+1))=131.
THEN compare the value of b with c(if b==c)
then
is pallin
else
not pallin

Are you serious?
Ok basically, a string is palindrome if you read it normally is the same as reading it backwards. Examples are available here:
http://www.palindromelist.com/Example: "Damn, I, Agassi, miss again! Mad!"
The tricky part is to ignore punctuations. So given a string, you first iterate through it's characters and copy to another string only if it is alphabets / numeric (using isalpha(char) function).
Example: "DamnIAgassimissagainMad"
Now you have a new version of the string, without spaces nor punctuations. But there is still one problem. Lower/Upper case. So re-iterate (or do it while you were copying in the step above) and use tolower(char) function to convert to lower case (it'll stay lower case if you pass an already lower case letter).
Example: "damniagassimissagainmad"
Finally, compare both ends of the string, moving inwards. You will want to loop for n = string.length() / 2 (because you're only reiterating half the size -- to the middle of the string).
Let i be the index for the left side, j be the index for the right side.
i = 0
j = string.length() - 1
every iteration of n times, increment i, decrement j, compare. Once they are not the same, immediately exit as we know it's not palindrome.
Else set a proper boolean then output that the string is palindrome.
Edit: Refer here for proper isxxxx functions you might need:
http://www.cplusplus.com/reference/clibrary/cctype/Once you've got the solution and feeling up for it, checkout functions from <algorithm>, comparing for palindrome after case conversion and stripped punctuations will be a one-liner.
This post has been edited by syazhani: 31 Mar, 2008 - 09:59 PM