#P8115. 「RdOI R3.5」Table

    ID: 9143 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟洛谷原创O2优化进制洛谷月赛

「RdOI R3.5」Table

Background

Little A wants to solve the problem by tabulating the answers, but the code is too long. He realized that writing numbers in hexadecimal can sometimes be shorter than writing them in decimal, so he decided to rewrite the answer table in hexadecimal.

Problem Description

In this problem, all “hexadecimal” numbers are written using digits 090\sim 9 and uppercase letters AF\tt A\sim F, and each hexadecimal number has the prefix 0x\colorbox{#ddd}{\tt 0x}.

You are given several decimal integers enclosed in braces and separated by commas, representing Little A’s answer table. You need to rewrite each number in the table as follows:

  • If the number of characters used when writing this integer in hexadecimal is less than or equal to that in decimal, rewrite it in hexadecimal.
  • Otherwise, keep it in decimal unchanged.

Output the rewritten answer table.

Input Format

  • Read one line containing a string. The string contains only braces, commas, and digits, with no spaces or other characters. The exact format can refer to the array definition format in C++. It represents Little A’s answer table, and the format is guaranteed to be correct.

Output Format

  • Output one line containing a string, representing the rewritten answer table.
{1,314159,3141592653589793}
{1,314159,0xB29430A256D21}

{}
{}

Hint

Sample Explanation

Sample #1

  • 11 is written in hexadecimal as 0x1\tt 0x1, which has 33 characters, longer than the 11 character in decimal.
  • 314159314159 is written in hexadecimal as 0x4CB2F\tt 0x4CB2F, which has 77 characters, longer than the 66 characters in decimal.
  • 31415926535897933141592653589793 is written in hexadecimal as 0xB29430A256D21\tt 0xB29430A256D21, which has 1515 characters, shorter than the 1616 characters in decimal.

Sample #2

The input is an empty array, so the output should also be an empty array.

Constraints and Notes

This problem has five test points. Each test point is worth 20 points, and the total score is the sum of the scores of all test points.

Suppose there are nn integers in the answer table, denoted as a1,a2,,ana_1,a_2,\cdots,a_n. For 100%100\% of the data, 0n1030\le n\le10^3, and 0ai<2640\le a_i < 2^{64}.

Translated by ChatGPT 5