33OJ
登录 注册

#P14357. [CSP-J 2025] 拼数

    ID: 16145 远端评测题 1000ms 512MiB 尝试: 44 已通过: 24 显示难度普及− 上传者: 标签>贪心2025O2优化排序CSP-J 入门级

[CSP-J 2025] 拼数

Problem Description

Little R is learning string processing. Little X gives Little R a string ss, where ss contains only lowercase English letters and digits, and contains at least one digit among 1∼91 \sim 9. Little X wants Little R to use any number of the digits in ss, in any order, to form a positive integer. Note: Little R may choose identical digits in ss, but each digit can be used only once. For example, if ss is 1a01b\tt 1a01b, then Little R may choose the 11-st, 33-rd and 44-th characters at the same time, which are 1,0,11, 0, 1, and form the positive integer 101101 or 110110; however, Little R cannot form the positive integer 111111, because ss contains only two digits 11. Little R wants to know, among all the positive integers he can form, which one is the largest. You need to help Little R find the maximum positive integer he can form.

Input Format

The first line of input contains a string ss, representing the string Little X gives to Little R.

Output Format

Output one positive integer on a single line, representing the maximum positive integer Little R can form.

5
5
290es1q0
92100

Hint

Example 2 Explanation

ss contains the digits 2,9,0,1,02, 9, 0, 1, 0. It can be proven that the maximum positive integer Little R can form is 9210092100.

Example 3

See number/number3.in\textbf{\textit{number/number3.in}} and number/number3.ans\textbf{\textit{number/number3.ans}} in the contestant directory. This example satisfies the constraints of test points 9∼119 \sim 11.

Example 4

See number/number4.in\textbf{\textit{number/number4.in}} and number/number4.ans\textbf{\textit{number/number4.ans}} in the contestant directory. This example satisfies the constraints of test point 2020.

Constraints

Let ∣s∣|s| be the length of the string ss. For all test data, it is guaranteed that:

  • 1≤∣s∣≤1061 \leq |s| \leq 10^6;
  • ss contains only lowercase English letters and digits, and contains at least one digit among 1∼91 \sim 9.

::cute-table{tuack}

Test point ∣s∣≤\lvert s\rvert \leq Special property
11 A
22 ^
33 ^ None
44 1010 A
5,65,6 ^ None
7,87,8 10210^2 A
9∼119 \sim 11 ^ None
1212 10310^3 A
13,1413,14 ^ None
1515 10510^5 A
16,1716,17 ^ B
18,1918,19 None
2020 10610^6 A
21,2221,22 ^ B
23∼2523 \sim 25 None
  • Special property A: ss contains only digits.
  • Special property B: ss contains at most 10310^3 digits.

Translated by QwenWork