fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string>
  5.  
  6. bool is_palindrome(const std::string& str)
  7. {
  8. std::string copy(str);
  9. std::transform(copy.begin(), copy.end(), std::tolower);
  10.  
  11. if (copy.size() == 0)
  12. {
  13. return true;
  14. }
  15.  
  16. auto rfirst = copy.rbegin();
  17. auto rlast = --copy.rend();
  18. while (rfirst != rlast)
  19. {
  20. if (*rfirst++ != *rlast--)
  21. return false;
  22. }
  23.  
  24. return true;
  25. }
  26.  
  27. int main()
  28. {
  29. std::string str{ "KArak" };
  30. std::cout << std::boolalpha;
  31. std::cout << "is \"KArak\" palindrome? " << is_palindrom(str) << '\n';
  32. std::cout << "is \"fuf\" palindrome? " << is_palindrom("fuf") << '\n';
  33. std::cout << "is empty string palindrome? " << is_palindrom("") << '\n';
  34. return 0;
  35. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘bool is_palindrome(const string&)’:
prog.cpp:9:55: error: no matching function for call to ‘transform(std::__cxx11::basic_string<char>::iterator, std::__cxx11::basic_string<char>::iterator, <unresolved overloaded function type>)’
  std::transform(copy.begin(), copy.end(), std::tolower);
                                                       ^
In file included from /usr/include/c++/6/algorithm:62:0,
                 from prog.cpp:3:
/usr/include/c++/6/bits/stl_algo.h:4166:5: note: candidate: template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
     transform(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~
/usr/include/c++/6/bits/stl_algo.h:4166:5: note:   template argument deduction/substitution failed:
prog.cpp:9:55: note:   candidate expects 4 arguments, 3 provided
  std::transform(copy.begin(), copy.end(), std::tolower);
                                                       ^
In file included from /usr/include/c++/6/algorithm:62:0,
                 from prog.cpp:3:
/usr/include/c++/6/bits/stl_algo.h:4203:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter, class _BinaryOperation> _OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation)
     transform(_InputIterator1 __first1, _InputIterator1 __last1,
     ^~~~~~~~~
/usr/include/c++/6/bits/stl_algo.h:4203:5: note:   template argument deduction/substitution failed:
prog.cpp:9:55: note:   candidate expects 5 arguments, 3 provided
  std::transform(copy.begin(), copy.end(), std::tolower);
                                                       ^
prog.cpp: In function ‘int main()’:
prog.cpp:31:65: error: ‘is_palindrom’ was not declared in this scope
     std::cout << "is \"KArak\" palindrome? " << is_palindrom(str) << '\n';
                                                                 ^
stdout
Standard output is empty