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. package包

    为什么需要package? 为了解决类之间的重名问题.为了方便管理类,合适的类放在合适的包. 怎么用package? 通常是类的第一句非注释性语句. 包名,域名倒着写,加上模块名,并与内部管理类. 命 ...

  2. String实例 (练习)

    练习题1:用户输入一段字符串,要求统计出在该段字符串中,数字,字母以及其他字符各出现过几次??? 代码实现: 运行结果:  补充:1. 连接符的使用: +用作连接符时,只能连接字符串,即“    ”双 ...

  3. 如何利用border书写三角形,建议考虑正方形

    网页做三角形图片,你还在拿ps调整吗?out了,老铁,来和我一起脑海畅想一个正方形是由4个等腰直角三角形构成,然后我想保留上边的三角形,那下边.左边.右边的三角形就没了(设置背景色transparen ...

  4. Kubernetes CI/CD(2)

    本章节通过在Jenkins创建一个kubernetes云环境,动态的在kubernetes集群中创建pod完成pipeline的构建流程,关于直接在宿主机上搭建Jenkins集群的可参照Kuberne ...

  5. Android Studio 快捷方式记录

  6. w13scan扫描器的使用

    0x01 w13scan第三方包下载 环境:python3以上 下载:pip install w13scan 0x02 利用w13scan API接口编写w13scan.py from W13SCAN ...

  7. 10maven依赖继承、统一版本/编码

    A >  B  >  C A依赖于B,B依赖于C,如果A想间接依赖C,那么B和C之间的依赖范围必须是compile,不然A依赖不了C 但是有点麻烦,因为每次A想依赖于C都要确认B和C之间的 ...

  8. XSY3163

    题意 \(n\)阶无向图,带边权,边有黑白两色,问有多少棵白边恰好为\(k\)的树,边权最小 做法 先二分出给白边的附加权值,然后矩阵树讨论同权值块即可 题外话 乍一看好神仙,然后..

  9. JPA 常用注解

    @Entity(name=”EntityName”):必须,name为可选,对应数据库中一的个表 @Table(name=””,catalog=””,schema=””):可选 通常和@Entity配 ...

  10. 吴裕雄--天生自然 PYTHON数据分析:所有美国股票和etf的历史日价格和成交量分析

    # This Python 3 environment comes with many helpful analytics libraries installed # It is defined by ...