308773: CF1573A. Countdown
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Countdown
题意翻译
**题目描述** 给定一个字符串,定义一次操作为将字符串的最后一位 $-1$,或交换字符串中的任意两位。求把字符串所有位变成 $0$ 的最少操作次数。 **输入格式** 第一行一个整数 $t$,为测试数据的组数。 接下来 $2\times t$ 行,每两行一个数字和一个字符串,分别表示字符串的长度和字符串。详细信息见题目描述。 **输出格式** 共 $t$ 行,一行一个正整数,为把字符串所有位变成 $0$ 的最少操作次数。 **说明/提示** 对于 $100\%$ 的数据,$1\le t\le10^3$,$1\le n\le 100$,$0\le s_1,s_2,\cdots,s_n\le 9$。 对于第一组询问,只需要将末尾操作 $7$ 次即可符合要求。输出 $7$。 对于第二组询问,交换首位和末尾,再将末尾 $-1$,共进行 $2$ 次操作。输出 $2$。 对于第三组询问,字符串已经全部为 $0$,故不需要进行任何操作。输出 $0$。 translate by @[159号程序员](https://www.luogu.com.cn/user/334586)题目描述
You are given a digital clock with $ n $ digits. Each digit shows an integer from $ 0 $ to $ 9 $ , so the whole clock shows an integer from $ 0 $ to $ 10^n-1 $ . The clock will show leading zeroes if the number is smaller than $ 10^{n-1} $ . You want the clock to show $ 0 $ with as few operations as possible. In an operation, you can do one of the following: - decrease the number on the clock by $ 1 $ , or - swap two digits (you can choose which digits to swap, and they don't have to be adjacent). Your task is to determine the minimum number of operations needed to make the clock show $ 0 $ .输入输出格式
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^3 $ ). The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 100 $ ) — number of digits on the clock. The second line of each test case contains a string of $ n $ digits $ s_1, s_2, \ldots, s_n $ ( $ 0 \le s_1, s_2, \ldots, s_n \le 9 $ ) — the number on the clock. Note: If the number is smaller than $ 10^{n-1} $ the clock will show leading zeroes.
输出格式
For each test case, print one integer: the minimum number of operations needed to make the clock show $ 0 $ .
输入输出样例
输入样例 #1
7
3
007
4
1000
5
00000
3
103
4
2020
9
123456789
30
001678294039710047203946100020
输出样例 #1
7
2
0
5
6
53
115