#include <iostream>
#include <limits.h>
using namespace std;
int reverse(int x) {
//to accomodate overflowed reversed value if occured
long revX = 0;
while (x != 0) {
revX = revX * 10 + x % 10;
//overflow check
if (revX > INT_MAX || revX < INT_MIN) {
return 0;
}
x /= 10;
}
return (int) revX;
}
int main() {
int x = -321;
cout << reverse(x);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGltaXRzLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcmV2ZXJzZShpbnQgeCkgewogICAgLy90byBhY2NvbW9kYXRlIG92ZXJmbG93ZWQgcmV2ZXJzZWQgdmFsdWUgaWYgb2NjdXJlZAogICAgbG9uZyByZXZYID0gMDsKICAgIHdoaWxlICh4ICE9IDApIHsKICAgICAgICByZXZYID0gcmV2WCAqIDEwICsgeCAlIDEwOwogICAgICAgIC8vb3ZlcmZsb3cgY2hlY2sKICAgICAgICBpZiAocmV2WCA+IElOVF9NQVggfHwgcmV2WCA8IElOVF9NSU4pIHsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIHggLz0gMTA7CiAgICB9CiAgICByZXR1cm4gKGludCkgcmV2WDsKfQoKaW50IG1haW4oKSB7CglpbnQgeCA9IC0zMjE7Cgljb3V0IDw8IHJldmVyc2UoeCk7CglyZXR1cm4gMDsKfQ==