P1553 Digit Reversal (Enhanced Edition)
Background
The following is the original statement, for reference only:
Given a number, reverse the digits in each place to obtain a new number.
Unlike NOIp2011 Junior Problem 1, this time the number can be a decimal, a fraction, a percentage, or an integer. Integer reversal means reversing all digits. Decimal reversal means reversing the digits of the integer part and the digits of the fractional part separately, without swapping the integer and fractional parts. Fraction reversal means reversing the digits of the denominator and then the digits of the numerator, without swapping the numerator and the denominator. For a percentage, the numerator is always an integer, and only the digits are changed. The new integer must satisfy the normal integer form: unless the given original number is zero, the highest digit of the reversed integer must not be zero. The new decimal must not end with $0$ (unless the fractional part contains nothing but $0$, in which case keep exactly one $0$). Fractions are not reduced, and neither the numerator nor the denominator is a decimal (the input guarantees that the denominator is not $0$). There are no negative numbers.
Description
Given a number, reverse the digits in each place to obtain a new number.
Unlike NOIp2011 Junior Problem 1, this time the number can be a decimal, a fraction, a percentage, or an integer.
- Integer reversal: reverse all digits.
- Decimal reversal: reverse the digits of the integer part and the digits of the fractional part separately, without swapping the integer and fractional parts.
- Fraction reversal: reverse the digits of the denominator, then reverse the digits of the numerator, without swapping the numerator and the denominator.
- Percentage: the numerator is always an integer; only the digits are changed.
Input Format
A number $s$.
Output Format
A number: the reversed form of $s$.
Explanation/Hint
Constraints
- For $25\%$ of the testdata, $s$ is an integer with at most $20$ digits.
- For $25\%$ of the testdata, $s$ is a decimal, and both its integer part and fractional part have at most $10$ digits.
- For $25\%$ of the testdata, $s$ is a fraction, and both its numerator and denominator have at most $10$ digits.
- For $25\%$ of the testdata, $s$ is a percentage, and its numerator has at most $19$ digits.
Data Guarantees
- For integer reversal, both the original integer and the reversed integer satisfy the normal integer form: unless the original number is zero, the highest digit of both the original and the reversed number must not be zero.
- For decimal reversal, the part before the decimal point follows the same rule as integers. The part after the decimal point satisfies the normal decimal form, i.e., there are no extra trailing $0$s (if the fractional part has nothing but $0$, keep exactly $1$ zero. If trailing zeros appear after reversal, omit the extra $0$s).
- For fraction reversal, the fraction is not reduced, and neither the numerator nor the denominator is a decimal. The input denominator is not $0$. Rules related to integer reversal apply as above.
- For percentage reversal, see the rules related to integers.
There are no negative numbers in the testdata.
Translated by ChatGPT 5