FirstHack Learn
Log in Sign up free
← All problems

Reverse a Number

Easy 2 solved

Reverse a Number

Given a non-negative integer N, print the number formed by reversing its digits.

For example 12345 becomes 54321.

Leading zeros disappear in the reversed number: reversing 1200 gives 21, not 0021. A single digit reverses to itself.

💡

The classic method uses N % 10 to pull off the last digit and N / 10 (integer division) to drop it.

Input

A single line containing one integer N.

Output

A single integer: the digits of N in reverse order.

Constraints

0 <= N <= 10^9

Example 1
Input
12345
Output
54321

The digits 1 2 3 4 5 read backwards are 5 4 3 2 1.

Submit runs your code against 5 test cases — the 1 shown above plus 4 hidden ones covering the awkward cases. Run sample just tries the first example, which is usually what you want while you are still working it out.