309464: CF1684A. Digit Minimization

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Digit Minimization

题意翻译

### 题目描述 有一个用十进制表示的没有前导零的正整数 $n$ 。Alice 和 Bob 正在用这个数玩一个游戏。Alice 先手,他们轮流进行游戏。 在她的这一轮中,Alice 应该交换这个数中的任何不同位置的两位。轮到 Bob 时,他每次都会删除这个数的末一位。当这个数只剩一位时,游戏结束。 你需要找出 Alice 用最佳方法在最后找出的最小数。 ### 输入格式 本题有多组数据。 输入数据第一行包含一个正整数 $t$($1 \le t \le 10^4$),表示数据组数。 接下来 $t$ 行,每行包含一个正整数 $n$($10 \le n \le 10^9$),表示游戏中用到的这个正整数,$n$ 在十进制表示中不含前导零。 ### 输出格式 输出 $t$ 行,每行输出一个正整数,表示游戏结束时 Alice 能得到的最小数。 ### 输入输出样例解释 在第一个测试数据中,Alice 将 $1$ 和 $2$ 交换,然后 Bob 又将最后一位 $1$ 删除。最后得到结果 $2$。 在第二个测试数据中,Alice 将 $3$ 和 $1$ 交换,变成 $312$。然后 Bob 将最后一位 $2$ 删除,变成 $31$。接着 Alice 将 $3$ 和 $1$ 交换,变成 $13$。最后 Bob 将最后一位删除,得到最终的结果 $1$。

题目描述

There is an integer $ n $ 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.

输入输出格式

输入格式


The input consists of multiple test cases. The first line contains a single integer $ t $ ( $ 1 \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 $ n $ ( $ 10 \le n \le 10^9 $ ) — the integer for the game. $ n $ does not have zeros in its decimal representation.

输出格式


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 $ 1 $ and $ 2 $ . After that Bob removes the last digit, $ 1 $ , so the answer is $ 2 $ . In the second test case Alice can swap $ 3 $ and $ 1 $ : $ 312 $ . After that Bob deletes the last digit: $ 31 $ . Then Alice swaps $ 3 $ and $ 1 $ : $ 13 $ and Bob deletes $ 3 $ , so the answer is $ 1 $ .

Input

题意翻译

### 题目描述 有一个用十进制表示的没有前导零的正整数 $n$ 。Alice 和 Bob 正在用这个数玩一个游戏。Alice 先手,他们轮流进行游戏。 在她的这一轮中,Alice 应该交换这个数中的任何不同位置的两位。轮到 Bob 时,他每次都会删除这个数的末一位。当这个数只剩一位时,游戏结束。 你需要找出 Alice 用最佳方法在最后找出的最小数。 ### 输入格式 本题有多组数据。 输入数据第一行包含一个正整数 $t$($1 \le t \le 10^4$),表示数据组数。 接下来 $t$ 行,每行包含一个正整数 $n$($10 \le n \le 10^9$),表示游戏中用到的这个正整数,$n$ 在十进制表示中不含前导零。 ### 输出格式 输出 $t$ 行,每行输出一个正整数,表示游戏结束时 Alice 能得到的最小数。 ### 输入输出样例解释 在第一个测试数据中,Alice 将 $1$ 和 $2$ 交换,然后 Bob 又将最后一位 $1$ 删除。最后得到结果 $2$。 在第二个测试数据中,Alice 将 $3$ 和 $1$ 交换,变成 $312$。然后 Bob 将最后一位 $2$ 删除,变成 $31$。接着 Alice 将 $3$ 和 $1$ 交换,变成 $13$。最后 Bob 将最后一位删除,得到最终的结果 $1$。

Output

题目大意:有一个十进制表示的正整数 $ n $,没有前导零。Alice 和 Bob 在这个数上进行游戏,Alice 先手,轮流进行。Alice 可以交换任意两位数字,Bob 则删除最后一位数字。当数字只剩一位时,游戏结束。求 Alice 通过最佳操作得到的最小数字。

输入格式:第一行包含一个正整数 $ t $($ 1 \le t \le 10^4 $),表示数据组数。接下来 $ t $ 行,每行包含一个正整数 $ n $($ 10 \le n \le 10^9 $),$ n $ 在十进制表示中不含前导零。

输出格式:输出 $ t $ 行,每行输出一个正整数,表示游戏结束时 Alice 能得到的最小数。

输入输出样例解释:在第一个测试数据中,Alice 将 $1$ 和 $2$ 交换,然后 Bob 又将最后一位 $1$ 删除。最后得到结果 $2$。在第二个测试数据中,Alice 将 $3$ 和 $1$ 交换,变成 $312$。然后 Bob 将最后一位 $2$ 删除,变成 $31$。接着 Alice 将 $3$ 和 $1$ 交换,变成 $13$。最后 Bob 将最后一位删除,得到最终的结果 $1$。题目大意:有一个十进制表示的正整数 $ n $,没有前导零。Alice 和 Bob 在这个数上进行游戏,Alice 先手,轮流进行。Alice 可以交换任意两位数字,Bob 则删除最后一位数字。当数字只剩一位时,游戏结束。求 Alice 通过最佳操作得到的最小数字。 输入格式:第一行包含一个正整数 $ t $($ 1 \le t \le 10^4 $),表示数据组数。接下来 $ t $ 行,每行包含一个正整数 $ n $($ 10 \le n \le 10^9 $),$ n $ 在十进制表示中不含前导零。 输出格式:输出 $ t $ 行,每行输出一个正整数,表示游戏结束时 Alice 能得到的最小数。 输入输出样例解释:在第一个测试数据中,Alice 将 $1$ 和 $2$ 交换,然后 Bob 又将最后一位 $1$ 删除。最后得到结果 $2$。在第二个测试数据中,Alice 将 $3$ 和 $1$ 交换,变成 $312$。然后 Bob 将最后一位 $2$ 删除,变成 $31$。接着 Alice 将 $3$ 和 $1$ 交换,变成 $13$。最后 Bob 将最后一位删除,得到最终的结果 $1$。

加入题单

算法标签: