fork(2) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. bool is_palidrome(std::string inputString) {
  5. auto num_to_parse = inputString.size();
  6. auto middleOfString = num_to_parse / 2;
  7.  
  8. for (decltype(num_to_parse) i = 0; i < middleOfString; ++i) {
  9. if (inputString[i] != inputString[num_to_parse-i-1]) {
  10. return false;
  11. }
  12. }
  13.  
  14. return true;
  15. }
  16.  
  17.  
  18. int main() {
  19. // Change the value of inputString to test different palindromes
  20. std::string inputString = "caabaac";
  21.  
  22. if (is_palidrome(inputString)) {
  23. std::cout << "This is a palindrome." << std::endl;
  24. } else {
  25. std::cout << "Not a palindrome." << std::endl;
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
This is a palindrome.