Question link: https://pintia.cn/problem-sets/14/problems/783 The
program reads a positive 3 digits each time, and then outputs the digits in reverse order. Note: When the input number contains a trailing 0, the output should not have a leading 0. For example, if you enter 700, the output should be 7.
Input format:
Each test is a 3-digit positive integer.
Output format:
output the number in bit reverse order.
Input sample:
123
Sample output:
321
Problem-solving ideas:
This question is quite easy to write in Python. First, let me talk about my idea:
read a string, call to .strip('0')
delete the 0 at the beginning and the end, then [::-1]
flip the string, and output it.
Of course, it can also be reversed directly. Calling the int()
function can also remove the leading 0 after the string is reversed.
AC code
print(input().strip('0')[::-1])