Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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.

Sample Input

Input
  1. 5
    82195
    64723
Output
  1. 13

Hint

In the sample he needs 13 moves:

  • 1 disk: 
  • 2 disk: 
  • 3 disk: 
  • 4 disk: 
  • 5 disk: 

过五反向求,水水。

附AC代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6. int n;
  7. char a[],b[];
  8. int x[],y[];
  9.  
  10. int main(){
  11. while(cin>>n){
  12. cin>>a>>b;
  13. for(int i=;i<n;i++){
  14. x[i]=a[i]-'';
  15. y[i]=b[i]-'';
  16. }
  17. int sum=;
  18. for(int i=;i<n;i++){
  19. if(abs(x[i]-y[i])>)
  20. sum+=(-abs(x[i]-y[i]));
  21. else
  22. sum+=abs(x[i]-y[i]);
  23. }
  24. cout<<sum<<endl;
  25. }
  26. return ;
  27. }

A - Combination Lock的更多相关文章

  1. Combination Lock

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

  2. hihocoder #1058 Combination Lock

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

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

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

  4. 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 ...

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

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

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

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

  7. hihocoder-第六十一周 Combination Lock

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

  8. HDU 3104 Combination Lock(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3104 Problem Description A combination lock consists ...

  9. 洛谷 P2693 [USACO1.3]号码锁 Combination Lock

    P2693 [USACO1.3]号码锁 Combination Lock 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...

随机推荐

  1. vue-导入静态文件

    vue导入静态文件不用像网上说的那么麻烦,其实跟普通Django项目导入类似,vue项目中有一个static文件,将你的静态文件放入到里面,然后引入就好 导入的时候和普通Django程序类似:↓ &l ...

  2. canvas 星空插件

    (function(a){ a.fn.starBg=function(p){ var p=p||{}; var w_w=p&&p.window_width?p.window_width ...

  3. IMDB-WIKI - 具有年龄和性别标签的500k +脸部图像

    Rasmus Rothe, Radu Timofte, Luc Van Gool DEX:从单一形象深刻地看待年龄 观看 人物研讨会国际计算机视觉大会(ICCV),2015*获胜LAP面对年龄估计的挑 ...

  4. 如何学习Java?

    一点感悟 java作为一门编程语言,在各类编程语言中作为弄潮儿始终排在前三的位置,这充分肯定了java语言的魅力,在实际项目应用中,我们已经无法脱离javaa(Ps当然你可以选择不使用),但它的高性能 ...

  5. Redis 3.2.4编译安装

    1. 下载安装包 wget url tar zxvf redis-3.2.4.tar.gz 2. 编译安装 cd redis-3.2.4/src/ sudo make && make ...

  6. Angularv4入门篇1

    国庆时按照官网的tutorial写了遍官方示例,一知半解,不明白angular的服务的服务为何要单独抽离出来.angular应用是如何启用的.近期打算看下angular的文档部分,然后梳理遍以理解an ...

  7. Android活动条(actionbar)使用具体解释(一)

        活动条(ActionBar)是Android3.0的重要更新之中的一个.ActionBar位于传统标题的位置,其主要提供了例如以下功能:     >显示选项菜单的菜单项,即激昂菜单项显示 ...

  8. SQL 关联操作

  9. AndroidPageObjectTest_ByAllPossible.java

    以下代码使用ApiDemos-debug.apk进行测试 //这个脚本用于演示PageFactory的功能:使用注解@AndroidFindAll定位元素.注解用法参考页面类代码. package c ...

  10. 7-12 畅通工程之最低成本建设问题(30 point(s)) 【PRIME】

    7-12 畅通工程之最低成本建设问题(30 point(s)) 某地区经过对城镇交通状况的调查,得到现有城镇间快速道路的统计数据,并提出"畅通工程"的目标:使整个地区任何两个城镇间 ...