fork download
  1. #include <string>
  2. #include <cctype>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. bool is_palindrome( const std::string& str )
  7. {
  8. std::string s ;
  9. for( char c : str ) if( std::isalpha(c) ) s += std::toupper(c) ;
  10. return !s.empty() && std::equal( s.begin(), s.begin() + s.size()/2, s.rbegin() ) ;
  11. }
  12.  
  13. int main()
  14. {
  15. const char* const phrases[]
  16. {
  17. "A man, a plan, a canal - Panama!", // yes
  18. "not palindrome", // no
  19. "No lemon, no melon", // yes
  20. "Not lemon, not melon", // almost, but no
  21. "Never odd or even" // yes
  22. };
  23. for( auto cstr : phrases ) if( is_palindrome(cstr) ) std::cout << cstr << '\n' ;
  24. }
  25.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
A man, a plan, a canal - Panama!
No lemon, no melon
Never odd or even