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

前端 未结 9 576
悲哀的现实
悲哀的现实 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 16:05

    Here's a shorter solution (C++; identical line count for C):

    bool is_p(char const * const str, ptrdiff_t n)
    {
      if (n < 1) return false;
    
      auto p = str, q = str + n - 1;
      while (*(p++) == *(q--))
        if (p >= q)
          return true;
      return false;
    }
    

提交回复
热议问题