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