fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool validCharacter(char c) {
  6. return isalpha(c);
  7. }
  8.  
  9. bool isP(const string& s) {
  10. int lo = 0;
  11. int hi = s.size() - 1;
  12. while (lo < hi) {
  13. while (!validCharacter(s[lo])) {
  14. ++lo;
  15. }
  16. while (!validCharacter(s[hi])) {
  17. --hi;
  18. }
  19. if (tolower(s[lo]) != tolower(s[hi])) {
  20. return false;
  21. }
  22. ++lo;
  23. --hi;
  24. }
  25. return true;
  26. }
  27.  
  28. int main() {
  29. string s = "tab a cat";
  30. cout << isP(s) << endl;
  31. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
0