The return string.

Source: Internet
Author: User

The return string.

Question: judge whether a string is a return string. The so-called return string means that the I character of the string is equal to the n + 1-i character of the string, and the I is less than or equal to n/2. For example, "abcba" and "abba" are all input strings.


Solution:

The Nth + 1-i character of the string is equal to the nth + 1-i character of the string. If I is less than or equal to n/2, false is returned, if the execution of the loop is complete, true is returned.


Algorithm Implementation:

Bool isPalindromeStr (char str []) {if (str = NULL | str = NULL) {printf ("the string is NULL or empty, not a return string "); return false;} int n = 0; // String Length while (str [n]! = '\ 0') {n ++;} for (int I = 0; I <n/2; I ++) {if (str [I]! = Str [n-i-1]) return false;} return true ;}


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.