#K12661. Invert and Reverse

    ID: 23741 Type: Default 1000ms 256MiB

Invert and Reverse

Invert and Reverse

Given an integer, invert its sign and then reverse the order of its digits. In other words, if the input number n is positive, the result is -r where r is the integer obtained by reversing the digits of n. If n is negative, the result is the reversed digits of its absolute value. For n = 0, the output is 0.

The reversal should omit any leading zeros in the resulting number. For example, when n = -502 the absolute value is 502, and reversing it yields 205.

Mathematical Formulation: Given an integer \( n \), define the function as follows: \[ \text{result} = \begin{cases} -\text{reverse}(n) & \text{if } n > 0, \\ \text{reverse}(|n|) & \text{if } n < 0, \\ 0 & \text{if } n = 0, \end{cases} \] where \( \text{reverse}(x) \) denotes the integer obtained by writing the digits of \( x \) in reverse order (ignoring any leading zeros in the result).

inputFormat

A single line containing an integer.

outputFormat

Output the integer obtained after inverting the sign of the input and reversing its digits.## sample

123
-321