Problem 73
Reverse Integer
Easy · 10 pts · Math
Problem
You are given an integer N. Reverse the order of its decimal digits and keep its sign. Zeros that end up at the front of the reversed number are dropped, so 120 becomes 21, and -450 becomes -54. Work with the absolute value: repeatedly take the last digit (N mod 10) and append it to the result (result × 10 + digit). Put the minus sign back at the end if N was negative. Some values computed along the way can be larger than a 32-bit int can hold (about 2.1 × 10^9), even when the input looks small, so use a 64-bit integer type: long long in C++, long in Java (Python needs nothing special).
Input
A single integer N.
Output
Print N with its digits reversed.
Constraints
-1000000000 <= N <= 1000000000
Example input
123
Example output
321
Explanation
The digits of 123 are 1, 2, 3. Reversed they read 3, 2, 1, and the number is positive, so the answer is 321.