CF1684A.Digit Minimization

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is an integer nn without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.

On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.

You have to find the smallest integer Alice can get in the end, if she plays optimally.

有一个十进制表示中不含数字 00 的整数 nn。爱丽丝(Alice)和鲍勃(Bob)正在用这个整数进行一场游戏,爱丽丝先手,两人轮流进行操作。

在爱丽丝的回合中,她必须交换该整数中任意两个位于不同位置上的数字。而在鲍勃的回合中,他总是移除该整数的最后一位数字。当整数只剩下一位数字时,游戏结束。

你需要求出:若爱丽丝采取最优策略,最终所能得到的最小整数是多少?

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Description of the test cases follows.

The first and the only line of each test case contains the integer nn (10≤n≤10910 \le n \le 10^9) — the integer for the game. nn does not have zeros in its decimal representation.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(10≤n≤10910 \le n \le 10^9),即游戏所用的整数。nn 的十进制表示中不含数字 00。

输出格式

For each test case output a single integer — the smallest integer Alice can get in the end of the game.

对于每个测试用例,输出一个整数——即爱丽丝在游戏结束时能得到的最小整数。

输入输出样例

  • 输入#1

    3
    12
    132
    487456398

    输出#1

    2
    1
    3

说明/提示

In the first test case Alice has to swap 11 and 22. After that Bob removes the last digit, 11, so the answer is 22.

In the second test case Alice can swap 33 and 11: 312312. After that Bob deletes the last digit: 3131. Then Alice swaps 33 and 11: 1313 and Bob deletes 33, so the answer is 11.

在第一个测试用例中,Alice 必须交换 11 和 22。之后 Bob 删除最后一位数字 11,因此答案为 22。

在第二个测试用例中,Alice 可以交换 33 和 11:得到 312312。之后 Bob 删除最后一位数字:得到 3131。接着 Alice 交换 33 和 11:得到 1313,Bob 再删除 33,因此答案为 11。

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

首页