fork(2) download
  1. // Cに合わせて修正
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cctype>
  5.  
  6. int is_palindrome( std::string S ) {
  7. S.erase( std::copy_if ( S.begin(), S.end(), S.begin(), isalpha ), S.end() );
  8. std::transform( S.begin(), S.end(), S.begin(), ::toupper );
  9. return std::equal ( S.begin(), S.end(), S.rbegin() );
  10. }
  11.  
  12. // -----------------------------------------------------------------------------
  13. // http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1357191974/277
  14. //
  15. void check_palindrome(const char *cs) {
  16. printf("\"%s\" %s a palindrome.\n", cs, is_palindrome(cs) ? "is" : "is NOT");
  17. }
  18. int main() {
  19. check_palindrome("boo");
  20. check_palindrome("A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!");
  21. check_palindrome("A tin mug for a jar of gum, Nita.");
  22. check_palindrome("A Toyota! Race fast, safe car! A Toyota!");
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
"boo" is NOT a palindrome.
"A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!" is a palindrome.
"A tin mug for a jar of gum, Nita." is a palindrome.
"A Toyota! Race fast, safe car! A Toyota!" is a palindrome.