C + + asks all palindrome strings in a string and outputs the result (string manipulation)

Source: Internet
Author: User
#include <iostream> #include <string.h>using namespace std;bool check (char *str)//Determine if this is not a palindrome string. {int i = 0;int j = strlen (str) -1;while (i<j) {if (* (str+i)!=* (str+j)) return false;i++;j--;} return true;} void Get_str (char *str) {int n = strlen (str)-1;  Char *p = new char[n+1];strcpy (p,str); int i = 0;int J; for (; i<n;i++) {p+=i;j = N-i;while (j>0)//Here J does not equal 0, one character is also a literal , but it is not necessary that the palindrome we seek here is a >=2 string. {* (p+j+1) = ' + '; if (check (p)) {cout<<p<< "   "; Cout<<endl;} j--;} strcpy (P,STR);}} Thought is the beginning of the i=0, J=n began to//i, j--, know i>=j to i=0 the position of all the strings to find it again,//i++,j=n began to repeat the above operations.//.....//know I==n when the end, and outputs all palindrome strings evaluated. int main () {char s[]= "abaeedd"; Get_str (s); return 0;}

C + + asks all palindrome strings in a string and outputs the result (string manipulation)

Related Article

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.