#P8115. Conditional Hexadecimal Conversion in Answer Table
Conditional Hexadecimal Conversion in Answer Table
Conditional Hexadecimal Conversion in Answer Table
Given a set of decimal integers enclosed in curly braces and separated by commas, your task is to convert each integer to a new representation according to the following rule:
For each integer (n):
- Let its decimal representation be (D(n)), and its hexadecimal representation (using uppercase letters and with a prefix of
0x
) be (H(n)). That is, (H(n) = \tt 0x + \text{[hex digits of }n\text{ in uppercase]}). - If the number of characters in (H(n)) is less than or equal to the number of characters in (D(n)), output (H(n)) in place of (n).
- Otherwise, output (D(n)) unchanged.
The output should maintain the same format as the input: a set of numbers enclosed by curly braces and separated by commas.
For example, consider the number (1000000000): its decimal representation is 1000000000
(10 characters) and its hexadecimal representation is 0x3B9ACA00
(10 characters). Since 10 (\le) 10, it is converted to hexadecimal.
inputFormat
The input consists of a single line containing a list of non-negative decimal integers. The list is enclosed in curly braces {}
and the integers are separated by commas. There are no extra characters.
outputFormat
Output the modified answer table in a single line. The output must be enclosed in curly braces {}
, and the converted numbers should be separated by commas. For each number, if its hexadecimal representation (with prefix 0x
) has a number of characters less than or equal to its decimal representation, print the hexadecimal form; otherwise, print the original decimal form.
sample
{15, 16, 1000000000}
{15,16,0x3B9ACA00}