Advertisement
avr39ripe

cppPalindrom

Oct 14th, 2021
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement