CF540A.Combination Lock
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.

The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
史高治·麦克达克将他最珍贵的积蓄存放在家中的保险箱里,保险箱配备了一个组合锁。每次他想把通过正当手段获得的财宝存入其中时,都必须先打开这个锁。

该组合锁由 n 个可旋转的圆盘组成,每个圆盘上标有数字 0 至 9。史高治·麦克达克需要转动若干圆盘,使得各圆盘上显示的数字组合成一个秘密密码。在一次操作中,他可以将某个圆盘向前或向后旋转一位(即加 1 或减 1,模 10 运算)。特别地,一次操作即可从数字 0 转到 9,反之亦然。那么,他最少需要多少次操作才能达成目标?
输入格式
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of disks on the combination lock.
The second line contains a string of n digits — the original state of the disks.
The third line contains a string of n digits — Scrooge McDuck's combination that opens the lock.
第一行包含一个整数 n(1≤n≤1000)—— 密码锁上圆盘的数量。
第二行包含一个长度为 n 的数字字符串 —— 圆盘的初始状态。
第三行包含一个长度为 n 的数字字符串 —— 史高治·麦克老鸭的密码,该密码可打开密码锁。
输出格式
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
输出一个整数——史高治·麦克达克打开锁所需的最少移动次数。
输入输出样例
输入#1
5 82195 64723
输出#1
13
说明/提示
In the sample he needs 13 moves:
- 1 disk:

- 2 disk:

- 3 disk:

- 4 disk:

- 5 disk:

在该样例中,他需要 13 步:
- 1 个圆盘:

- 2 个圆盘:

- 3 个圆盘:

- 4 个圆盘:

- 5 个圆盘:

输入解题思路,AI测评打分。不知道怎么写?