fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isPalindrome(int x) {
  5. if(x < 0)
  6. return false;
  7.  
  8. int rem, revX = 0;
  9. int temp = x;
  10. while(temp > 0){
  11. rem = temp % 10;
  12. revX = revX * 10 + rem;
  13. temp = temp / 10;
  14. }
  15. return revX == x;
  16. }
  17.  
  18. int main() {
  19. int x = 12344321;
  20. cout << isPalindrome(x) << endl;
  21. cout << isPalindrome(-1 * x) << endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
1
0