fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Solution {
  5. public:
  6. bool isPalindrome(string& s) {
  7. string st = "";
  8. for (auto& c : s) {
  9. c = tolower(c);
  10. if (c >= 'a' and c <= 'z' or c >='0' and c<='9') {
  11. st += c;
  12. }
  13. }
  14. cout <<st<<endl;
  15.  
  16. int n = st.size();
  17. int l = 0, r = n - 1;
  18.  
  19. while (l <= r) {
  20. if (st[l] != st[r])
  21. return false;
  22. else {
  23. l++, r--;
  24. }
  25. }
  26.  
  27. return true;
  28. }
  29. };
  30.  
  31.  
  32. int main() {
  33. string s = "0P";
  34. Solution sol;
  35. bool ans = sol.isPalindrome(s);
  36. cout << ans;
  37. return 0;
  38. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
0p
0