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