#C13599. Reverse the Digits
Reverse the Digits
Reverse the Digits
You are given a single integer. Your task is to reverse its digits while retaining the negative sign if the number is negative. For example, given 12345
, the output should be 54321
and given -678
, the output should be -876
. Note that any leading zeros in the reversed number should be removed (e.g., 1000
becomes 1
).
The reversal process can be formally defined as follows:
Let \( n \) be an integer and \( s \) be its sign, i.e., \( s = -1 \) if \( n < 0 \) and \( s = 1 \) otherwise. Then, the reversed integer is:
[ reverse(n) = s \times \text{reverse}(\lvert n \rvert) ]
where \( \text{reverse}(\lvert n \rvert) \) denotes the integer obtained by reversing the digits of \( |n| \).
inputFormat
The input consists of a single line containing one integer \( n \). This integer can be positive, negative, or zero.
outputFormat
Output a single integer, which is the reverse of the digits of the input integer, preserving the sign.
## sample12345
54321