Reverse the Number
Practice this coding question on Coding Gurukul.
Problem statement
A puzzle kiosk reverses the decimal digits on numbered tokens. The result is displayed as an integer rather than as a fixed-width label, so zeroes that become leading zeroes disappear. The kiosk receives a batch of token numbers and needs to perform the same transformation for every token. You are implementing the numeric reverse operation. Your task For each nonnegative integer n, reverse the order of its decimal digits and print the resulting integer. Keep zeroes that remain between nonzero digits, but omit any leading zeroes in the reversed result. Process test cases independently. Important details The reverse of zero is zero. A number ending in several zeroes may become much shorter after reversal. This operation does not reverse the order of test cases, only the digits within each number. Worked example The digits of 1200 reverse to 0021, which as an integer is 21. Reversing 1002 gives 2001 because those zeroes remain inside the number.
Input format
First line: T. Next T lines: n.
Output format
Print the reversed integer for each test case.
Constraints
1 <= T <= 1000; 0 <= n <= 1000000000.
Sample input
2 1200 1002
Sample output
21 2001
Sign in to run or submit a solution in C++, Java or Python.