#C13248. Reverse Integer
Reverse Integer
Reverse Integer
Given a signed 32-bit integer \( n \), reverse its digits. If the reversed integer is out of the 32-bit signed integer range, i.e., if it is less than \( -2^{31} \) or greater than \( 2^{31}-1 \), return 0. Otherwise, return the reversed integer.
For example, if the input is 123
, the output should be 321
; if the input is -456
, the output should be -654
; and if reversing the integer causes an overflow, the output should be 0
.
inputFormat
The input consists of a single integer \( n \), provided via standard input.
outputFormat
Output the reversed integer. If the reversed integer overflows the 32-bit signed integer range \( [-2^{31}, 2^{31}-1] \), output 0
.
123
321