A16027 | Ranom Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
No, not "random" numbers.
Ranom digits are denoted by uppercase Latin letters from A to E. Moreover, the value of the letter A is $1$ , B is $10$ , C is $100$ , D is $1000$ , E is $10000$ .
A Ranom number is a sequence of Ranom digits. The value of the Ranom number is calculated as follows: the values of all digits are summed up, but some digits are taken with negative signs: a digit is taken with negative sign if there is a digit with a strictly greater value to the right of it (not necessarily immediately after it); otherwise, that digit is taken with a positive sign.
For example, the value of the Ranom number DAAABDCA is $1000 - 1 - 1 - 1 - 10 + 1000 + 100 + 1 = 2088$ .
You are given a Ranom number. You can change no more than one digit in it. Calculate the maximum possible value of the resulting number.
Ranom digits are denoted by uppercase Latin letters from A to E. Moreover, the value of the letter A is $1$ , B is $10$ , C is $100$ , D is $1000$ , E is $10000$ .
A Ranom number is a sequence of Ranom digits. The value of the Ranom number is calculated as follows: the values of all digits are summed up, but some digits are taken with negative signs: a digit is taken with negative sign if there is a digit with a strictly greater value to the right of it (not necessarily immediately after it); otherwise, that digit is taken with a positive sign.
For example, the value of the Ranom number DAAABDCA is $1000 - 1 - 1 - 1 - 10 + 1000 + 100 + 1 = 2088$ .
You are given a Ranom number. You can change no more than one digit in it. Calculate the maximum possible value of the resulting number.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
The only line of each test case contains a string $s$ ( $1 \le |s| \le 2 \cdot 10^5$ ) consisting of uppercase Latin letters from A to E — the Ranom number you are given.
The sum of the string lengths over all test cases does not exceed $2 \cdot 10^5$ .
The only line of each test case contains a string $s$ ( $1 \le |s| \le 2 \cdot 10^5$ ) consisting of uppercase Latin letters from A to E — the Ranom number you are given.
The sum of the string lengths over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, print a single integer — the maximum possible value of the number, if you can change no more than one digit in it.
输入输出样例
输入 #1
4 DAAABDCA AB ABCDEEDCBA DDDDAAADDABECD
输出 #1
11088 10010 31000 15886
In the first example, you can get EAAABDCA with the value $10000-1-1-1-10+1000+100+1=11088$ .
In the second example, you can get EB with the value $10000+10=10010$ .
In the second example, you can get EB with the value $10000+10=10010$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted