D/C + + development application: Palindrome string

Source: Internet
Author: User

Palindrome: A palindrome is the same string that is read and reread, for example: "Radar", "Able was I ere I saw Elba" and "a man a plan a canal Panama" (if spaces are omitted).

Write a recursive function testpalindrome that returns True when the string in the array is palindrome, or false. function ignores spaces and punctuation in a string.

#include <stdio.h>
/* 字符串 一半数 总个数*/
int charf(char d[],int k, int i)
{
if(d[k]==d[i-k]&&k==0)
return(1);
else if(d[k]==d[i-k])
charf(d,k-1,i); /*递归调用*/
else
return(0);
}
main()
{
int i=0,n=0;
char a,b[20];
while ((a=getchar())!='\n')
{
b[i]=a;
i++;
}
if(i%2==0)
n=charf(b,(i/2),i-1);
else
n=charf(b,(i/2-1),i-1);
if(n==0)
printf("不是回文");
else
printf("是回文");
getch();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.