Reverse Digits
EasyPractice library · +10 XPmathdigits
Given a non-negative integer N, print the integer formed by reversing its digits. For example, if N is 123, the output should be 321. If N is 500, the output should be 5. Leading zeros in the original number are ignored, and trailing zeros in the original number become leading zeros after reversal and are thus omitted. For example, 120 becomes 21.
Input
A single line containing the non-negative integer N.
Output
A single line containing the integer with its digits reversed.
Constraints
0 <= N <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
12345
Output
54321
Reversing 12345 gives 54321.
Example 2
Input
500
Output
5
Reversing 500 gives 005, which is interpreted as 5.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
12345
Example 2 input
500