fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. bool palindrome( const std::string& s, int i = 0 )
  5. {
  6. if ( i == s.size() )
  7. return true;
  8.  
  9. return s[ i ] == s[ s.size() - i - 1 ] && palindrome( s , i + 1 );
  10. }
  11.  
  12. int main()
  13. {
  14. using namespace std;
  15. cout << palindrome( "example" ) << endl; // Not palindrome
  16. cout << palindrome( "repaper" ) << endl; // Palindrome
  17. cout << palindrome( "rotator" ) << endl; // Palindrome
  18. cout << palindrome( "madam" ) << endl; // Palindrome
  19. cout << palindrome( "" ) << endl; // Palindrome
  20. cout << palindrome( "" ) << endl; // Palindrome
  21. }
  22.  
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
0
1
1
1
1
1