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?

Input

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.

Output

Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.

Examples
input
5
82195
64723
output
13
Note

In the sample he needs 13 moves:

  • 1 disk: 
  • 2 disk: 
  • 3 disk: 
  • 4 disk: 
  • 5 disk: 
 #include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
char a[],b[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
memset(a,,sizeof(a));
memset(b,,sizeof(b));
scanf("%s%s",&a,&b);
int s=;
for(int i=;i<n;i++){
int x=(int)a[i]-'';
int y=(int)b[i]-'';
if(x<y) swap(x,y);
s+=min(x-y,+y-x);
}
printf("%d\n",s);
}
return ;
}

Codeforces 540A - Combination Lock的更多相关文章

  1. CodeForces 540A Combination Lock (水题)

    题意:给定一个串数,表示一种密码锁,再给定一串密码,问你滑动最少的次数,把第一行变成第二行. 析:很简单么,反正只有0-9这个10个数字,那么就是把每一个数从正着滑和倒着滑中找出一个最小的即可,正着滑 ...

  2. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  3. Codeforces Round #301 (Div. 2) A. Combination Lock 暴力

    A. Combination Lock Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...

  4. B.Petr and a Combination Lock

    https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...

  5. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  6. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  7. Hiho----微软笔试题《Combination Lock》

    Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...

  8. CF #301 A :Combination Lock(简单循环)

    A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:

  9. hihocoder-第六十一周 Combination Lock

    题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...

随机推荐

  1. Python 钩子函数详解

    ###### 钩子函数 ``` import pluggy hookspec = pluggy.HookspecMarker('aaa') hookimpl = pluggy.HookimplMark ...

  2. Spark基础和RDD

    spark 1. Spark的四大特性 速度快 spark比mapreduce快的两个原因 基于内存 1. mapreduce任务后期在计算的是时候,每一个job的输出结果都会落地到磁盘,后续有其他的 ...

  3. Linux部署MongoDB

    下载安装包 打开网站 https://www.mongodb.com/download-center/community查找与Linux版本一致的MongoDB安装包.我这里选择安装包格式为tgz压缩 ...

  4. SQL server 游标用法

    declare @EmpCode varchar(50), @EmpName varchar(50), @EmpAddress varchar(200);declare curEmployee cur ...

  5. 防止或减少过拟合的方式(二)——Dropout

    当进行模型训练的时候,往往可能错过模型的最佳临界点,即当达到最大精度的时候再进行训练,测试集的精度会下降,这时候就会出现过拟合,如果能在其临界点处提前终止训练,就能得到表达力较强的模型,从而也避免了过 ...

  6. cisco 添加静态路由

    静态路由:由人,手动写出的路由条目就叫静态路由,永久有效,优先级最高,效率最高. 路由器是干啥的? 连接不同地址段的网络.屏蔽不同地址段的网络广播. 路由器有多个接口,至少得有2个吧,一边一个局域网. ...

  7. docker配置搭建gogs

    参考文献: https://www.yeboyzq.com/linux/ruanjiananzhuangweihu/1012.html https://www.jianshu.com/p/d92fd4 ...

  8. WebGL_0003:正则表达式查找字符串

    1,查找字符串,中间是变化的 files/assets/.*?/1/ .*? 表示中间是人一个字符

  9. sudo的简单用法

    su: Switch User, 以管理员身份运行某些命令: su -l root -c 'COMMAND' 但是想要限制某个用户只拥有一部分管理员权限,而不是拥有全部权限,这就需要用到sudo su ...

  10. sql注入常见绕过技巧

    参考链接:https://blog.csdn.net/huanghelouzi/article/details/82995313 https://www.cnblogs.com/vincy99/p/9 ...