Advertisement
avv210

Palindrome

Nov 2nd, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. std::string isPalindrome( std::string str )
  5. {
  6.     std::string revStr = str;
  7.     std::reverse( revStr.begin(), revStr.end() );
  8.     if( str == revStr )
  9.     {
  10.         return "Yay, it's a palindrome";
  11.     }
  12.  
  13.     else
  14.     {
  15.         return "Nah, it's not a palindrome";
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21.     int count;
  22.     std::string str;
  23.     std::string palindrome;
  24.     std::cin >> count;
  25.  
  26.     for ( int i = 0; i < count; i++ )
  27.     {
  28.         std::cin >> str;
  29.         palindrome = isPalindrome( str );
  30.     }
  31.  
  32.     for ( int i = 0; i < count; i++ )
  33.         std::cout << palindrome << std::endl;
  34.    
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement