to find if a given string is palindrome or is not palindrome

前端 未结 9 557
悲哀的现实
悲哀的现实 2020-11-30 15:36

I made a program to find if a entered string is palindrome or not palindrome but it always says that its not a palindrome

#include  
#include          


        
9条回答
  •  时光取名叫无心
    2020-11-30 15:53

    A C-flavored solution : )

    bool is_palindrome(const char* s) {
        const char* p = s;
        while (*p != '\0') ++p;
        while (s < p) if (*s++ != *--p) return false;
        return true;
    }
    

提交回复
热议问题