A16178 | Morning
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a four-digit pin code consisting of digits from $0$ to $9$ that needs to be entered. Initially, the cursor points to the digit $1$ . In one second, you can perform exactly one of the following two actions:
- Press the cursor to display the current digit,
- Move the cursor to any adjacent digit.
The image above shows the device you are using to enter the pin code. For example, for the digit $5$ , the adjacent digits are $4$ and $6$ , and for the digit $0$ , there is only one adjacent digit, $9$ .
Determine the minimum number of seconds required to enter the given four-digit pin code.
- Press the cursor to display the current digit,
- Move the cursor to any adjacent digit.
The image above shows the device you are using to enter the pin code. For example, for the digit $5$ , the adjacent digits are $4$ and $6$ , and for the digit $0$ , there is only one adjacent digit, $9$ .
Determine the minimum number of seconds required to enter the given four-digit pin code.
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \leq t \leq 10^4$ ) - the number of the test cases. This is followed by their description.
The single line of each test case describes the pin code as a string of length $4$ , consisting of digits from $0$ to $9$ .
The single line of each test case describes the pin code as a string of length $4$ , consisting of digits from $0$ to $9$ .
输出格式
For each test case, output the minimum number of seconds required to enter the given pin code.
输入输出样例
输入 #1
10 1111 1236 1010 1920 9273 0000 7492 8543 0294 8361
输出 #1
4 9 31 27 28 13 25 16 33 24
In the first test case, the cursor needs to be pressed $4$ times.
In the second test case, it can be done in $9$ seconds as follows:
- Press the cursor.
- Move the cursor to the digit $2$ .
- Press the cursor.
- Move the cursor to the digit $3$ .
- Press the cursor.
- Move the cursor to the digit $4$ .
- Move the cursor to the digit $5$ .
- Move the cursor to the digit $6$ .
- Press the cursor.
In the second test case, it can be done in $9$ seconds as follows:
- Press the cursor.
- Move the cursor to the digit $2$ .
- Press the cursor.
- Move the cursor to the digit $3$ .
- Press the cursor.
- Move the cursor to the digit $4$ .
- Move the cursor to the digit $5$ .
- Move the cursor to the digit $6$ .
- Press the cursor.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted