fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isPalindrome(const string &s) {
  5. int left = 0, right = s.length() - 1;
  6.  
  7. while (left < right) {
  8. if (s[left] != s[right])
  9. return false;
  10. left++;
  11. right--;
  12. }
  13.  
  14. return true;
  15. }
  16.  
  17. int main() {
  18. string S;
  19. cin >> S;
  20.  
  21. if (isPalindrome(S))
  22. cout << "YES" << endl;
  23. else
  24. cout << "NO" << endl;
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5276KB
stdin
banana
stdout
NO