fork download
  1. #include <iostream>
  2. using namespace std;
  3. // palindrone problems
  4. class Solution {
  5. public:
  6. bool isPalindrome(string s) {
  7. // Run the loop for the given problems
  8. for (auto& x : s) {
  9. x = tolower(x);
  10.  
  11. int n=s.size();
  12. for(int i=0;i<n/2;i++){
  13. if(s[i]==' '){
  14. i++;
  15.  
  16. if(s[i]=s[n-i-1]){
  17. // steps to remove the non-alphanumeric characters
  18. if(s[i]<'A'|| s[i]>'Z' && s[i]<'a' || s[i]>'z'){
  19. s.erase(i,1);
  20. i--;
  21. }
  22. return "true";
  23. }
  24.  
  25.  
  26. }
  27. }
  28. return "false";
  29.  
  30. }
  31. }
  32. };
  33. int main() {
  34. // your code goes here
  35. Solution s1;
  36. bool Palindrome1=s1.isPalindrome("race a car");
  37. cout<<Palindrome1;
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
1