CF1251C.Minimize The Integer

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a huge integer aa consisting of nn digits (nn is between 11 and 3⋅1053 \cdot 10^5, inclusive). It may contain leading zeros.

You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 22).

For example, if a=032867235a = 032867235 you can get the following integers in a single operation:

  • 302867235302867235 if you swap the first and the second digits;
  • 023867235023867235 if you swap the second and the third digits;
  • 032876235032876235 if you swap the fifth and the sixth digits;
  • 032862735032862735 if you swap the sixth and the seventh digits;
  • 032867325032867325 if you swap the seventh and the eighth digits.

Note, that you can't swap digits on positions 22 and 44 because the positions are not adjacent. Also, you can't swap digits on positions 33 and 44 because the digits have the same parity.

You can perform any number (possibly, zero) of such operations.

Find the minimum integer you can obtain.

Note that the resulting integer also may contain leading zeros.

给你一个由 nn 位数字组成的极大整数 aa(nn 的取值范围为 11 到 3⋅1053 \cdot 10^5,含端点)。该整数可能包含前导零。

你可以在相邻(即位置相邻)的两个位置上交换数字,当且仅当这两个数字的奇偶性不同(即它们除以 22 的余数不同)。

例如,若 a=032867235a = 032867235,则一次操作可得到以下整数:

  • 302867235302867235:交换第 11 位与第 22 位;
  • 023867235023867235:交换第 22 位与第 33 位;
  • 032876235032876235:交换第 55 位与第 66 位;
  • 032862735032862735:交换第 66 位与第 77 位;
  • 032867325032867325:交换第 77 位与第 88 位。

注意:你不能交换位置 22 和 44 上的数字,因为这两个位置不相邻;你也不能交换位置 33 和 44 上的数字,因为这两个数字奇偶性相同。

你可以执行任意次数(包括零次)这样的操作。

请找出你能得到的最小整数。

注意:结果整数也可能包含前导零。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the input.

The only line of each test case contains the integer aa, its length nn is between 11 and 3⋅1053 \cdot 10^5, inclusive.

It is guaranteed that the sum of all values nn does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入中测试用例的数量。

每个测试用例仅有一行,包含整数 aa,其长度 nn 在 11 到 3⋅1053 \cdot 10^5 之间(含端点)。

保证所有 nn 的总和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case print line — the minimum integer you can obtain.

对于每个测试用例,输出一行——你能得到的最小整数。

输入输出样例

  • 输入#1

    3
    0709
    1337
    246432

    输出#1

    0079
    1337
    234642

说明/提示

In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): 070‾9→00790 \underline{\textbf{70}} 9 \rightarrow 0079.

In the second test case, the initial integer is optimal.

In the third test case you can perform the following sequence of operations: 24643‾2→2463‾42→243‾642→234642246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642.

在第一个测试用例中,你可以执行以下操作序列(被交换的数字对已加粗并高亮显示):070‾9→00790 \underline{\textbf{70}} 9 \rightarrow 0079。

在第二个测试用例中,初始整数已是最优解。

在第三个测试用例中,你可以执行以下操作序列:24643‾2→2463‾42→243‾642→234642246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642。

输入解题思路,AI测评打分。不知道怎么写?

首页