#K36442. Reverse Integer Digits
Reverse Integer Digits
Reverse Integer Digits
Given an integer \( n \), your task is to reverse its digits and output the reversed integer. If \( n \) is negative, the reversed integer must also be negative. Specifically, if \( n \) is represented as:
[ n = \mathrm{sign}(n) \times |n|, ]
then the reversed integer is defined as:
[ f(n) = \mathrm{sign}(n) \times \text{reverse}(|n|), ]
where reverse(|n|)
denotes the integer formed by the digits of \(|n|\) in reverse order, omitting any leading zeros.
Example:
- If
n = 123
, then the output should be321
. - If
n = -456
, then the output should be-654
. - If
n = 100
, then the output should be1
(leading zeros are dropped).
You need to implement a solution that reads from standard input (stdin) and writes the output to standard output (stdout).
inputFormat
The input consists of one single line containing a single integer \( n \), which can be positive, negative, or zero.
Input Format:
outputFormat
Output the reversed integer. The result should not include any leading zeros.
Output Format:
result## sample
123
321