CF1883A.Morning
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
给你一个由数字 0 到 9 组成的四位数密码,需要输入该密码。初始时,光标指向数字 1。每秒钟,你恰好可以执行以下两种操作之一:
- 按下当前光标所在位置的数字(即输入该数字),
- 将光标移动到任意一个相邻的数字上。

上图展示了你用来输入密码的设备。例如,数字 5 的相邻数字是 4 和 6;而数字 0 只有一个相邻数字,即 9。
求输入给定四位密码所需的最少秒数。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) - 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.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例占一行,以长度为 4 的字符串形式描述密码,该字符串由数字 0 至 9 组成。
输出格式
For each test case, output the minimum number of seconds required to enter the given pin code.
对于每个测试用例,输出输入给定 PIN 码所需的最少秒数。
输入输出样例
输入#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.
在第一个测试用例中,需要按压光标 4 次。
在第二个测试用例中,可以在 9 秒内完成,步骤如下:
- 按压光标。
- 将光标移动到数字 2。
- 按压光标。
- 将光标移动到数字 3。
- 按压光标。
- 将光标移动到数字 4。
- 将光标移动到数字 5。
- 将光标移动到数字 6。
- 按压光标。
输入解题思路,AI测评打分。不知道怎么写?