avr39ripe

cppPalindrom

Oct 14th, 2021
605
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. bool isPalindrom(const char* begin)
  4. {
  5.     auto end{ begin + strlen(begin) - 1};
  6.     for (; begin < end and *begin == *end; ++begin, --end);
  7.     return *begin == *end;
  8. }
  9.  
  10. int main()
  11. {
  12.     const int stringsNumber{ 6 };
  13.     char strings[stringsNumber][10]{"abba","abcba","a","","123","1222"};
  14.  
  15.     for (int i{ 0 }; i < stringsNumber; ++i)
  16.     {
  17.         std::cout << std::boolalpha << strings[i] << "\t:\t" << isPalindrom(strings[i]) << '\n';
  18.     }
  19.  
  20.     return 0;
  21. }
RAW Paste Data