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
5
82195
64723
Output
13

Hint

In the sample he needs 13 moves:

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

过五反向求,水水。

附AC代码:

 #include<iostream>
#include<cstring>
#include<cmath>
using namespace std; int n;
char a[],b[];
int x[],y[]; int main(){
while(cin>>n){
cin>>a>>b;
for(int i=;i<n;i++){
x[i]=a[i]-'';
y[i]=b[i]-'';
}
int sum=;
for(int i=;i<n;i++){
if(abs(x[i]-y[i])>)
sum+=(-abs(x[i]-y[i]));
else
sum+=abs(x[i]-y[i]);
}
cout<<sum<<endl;
}
return ;
}

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. Protostuff具体解释

    Protostuff具体解释 作者:chszs,未经博主同意不得转载. 经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 一.Protostuff介绍 Proto ...

  2. Java解析Property文件

    在Java项目中一些配置參数保存在Property文件里,这样能保证不改动原代码直接改动Property文件. PropertyParser.java package com.discover.par ...

  3. pyquery模块

    pyquery 这个模块基本是仿JQuery的形式,也支持CSS选择器语法,因此对于爬虫来说,避免了正则表达式的滥用. 创建对象 from pyquery import PyQuery as pq d ...

  4. Linux系统目录数和文件数限制

    对于系统管理员来说,了解系统的一些限制是非常有必要的,这样可以根据需要进行必要的参数配置和调整,进而实现更优的性能,对于系统设计人员甚至程序员来说,了解系统的一些限制,也会有助于设计更为合理的存储结构 ...

  5. sql无限级树型查询

    表结构如下: 表数据如下: 一提到无限级,很容易想到递归,使用sql 的CET语法如下 with menu(Id,Name,ParentId,Level) as ( select Id,Name,Pa ...

  6. (转) 实现wince datagrid 上下滑屏数据浏览

    开发 基于wince 手持设备数据库应用时 由于是触摸屏 当datagrid 数据过多 往往用户烦于去控制又窄又细的上下滚动条 尤其是高分辨率的屏上 (如魅族M8系统 720×480) 而且datag ...

  7. 判断一个IP地址是否是本局域网内地址

    //        /// <summary>        /// 判断一个IP地址是否是本局域网内地址,是返回true 否则返回false,        /// </summa ...

  8. Asynchronous programming with async and await (C#)

    Asynchronous Programming with async and await (C#) | Microsoft Docs https://docs.microsoft.com/en-us ...

  9. 在DuiLib中使用MFC类

    比如,想在DuiLib里使用MFC中的CInternetSession 首先,将Project Properties->General->Use of MFC设置为Use MFC in a ...

  10. UIView封装动画--iOS利用系统提供方法来做转场动画

    UIView封装动画--iOS利用系统提供方法来做转场动画 UIViewAnimationOptions option; if (isNext) { option=UIViewAnimationOpt ...