hbmy周赛1--E
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
5
82195
64723
13
Hint
In the sample he needs 13 moves:
- 1 disk:  
- 2 disk:  
- 3 disk:  
- 4 disk:  
- 5 disk:  
#include <iostream>
#include <cmath>
using namespace std; int main()
{
int n;
char a[1100];
char b[1100];
int flag= 0 ;
cin >> n;
for (int i=0; i<n; i++)
cin >> a[i];
for (int j=0; j<n; j++)
cin >> b[j];
int num = 0;
for (int i=0; i<n; i++)
{
int p1 = (int)a[i]-48;
int p2 = (int)b[i]-48;
int p = p1-p2;
flag = abs(p);
if (flag>5)
flag = 10-flag;
num = num +flag;
}
cout << num << endl;
return 0;
}
hbmy周赛1--E的更多相关文章
- hbmy周赛1--D
		D - Toy Cars Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ... 
- hbmy周赛1--C
		C - Exam Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ... 
- hbmy周赛1--B
		B - 改革春风吹满地 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ... 
- hbmy周赛1--A
		Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ... 
- 周赛-KIDx's Pagination                                                       分类:            比赛             2015-08-02 08:23    7人阅读    评论(0)    收藏
		KIDx's Pagination Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ... 
- 2015浙江财经大学ACM有奖周赛(一) 题解报告
		2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ... 
- Leetcode 第133场周赛解题报告
		今天参加了leetcode的周赛,算法比赛,要求速度比较快.有思路就立马启动,不会纠结是否有更好的方法或代码可读性.只要在算法复杂度数量级内,基本上是怎么实现快速就怎么来了. 比赛时先看的第二题,一看 ... 
- 牛客OI周赛9-提高组题目记录
		牛客OI周赛9-提高组题目记录 昨天晚上做了这一套比赛,觉得题目质量挺高,而且有一些非常有趣而且非常清奇的脑回路在里边,于是记录在此. T1: 扫雷 题目链接 设 \(f_i\) 表示扫到第 \(i\ ... 
- codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
		就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ... 
随机推荐
- .NET开发一个微信跳一跳辅助程序
			昨天微信更新了,出现了一个小游戏"跳一跳",玩了一下 赶紧还蛮有意思的 但纯粹是拼手感的,玩了好久,终于搞了个135分拿了个第一名,没想到过一会就被朋友刷下去了,最高的也就200来 ... 
- css:background-position > 精灵技术
			background-position : length || length background-position : position || position 取值: length : 百分数 ... 
- Effective Java 第三版——11. 重写equals方法时同时也要重写hashcode方法
			Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ... 
- Docker 安装入门 --基础镜像
			安装Docker1.Docker命令安装 yum install docker //安装docker包 service docker start //设置服务启动 chkconfig docker ... 
- type 命令详解
			type 作用: 用来显示指定命令的类型,判断出命令是内部命令还是外部命令. 命令类型: alias: 别名 keyword:关键字, shell 保留字 function:函数, shell函数 ... 
- Java集合(一) CopyOnWriteArrayList
			CopyOnWriteArrayList 类分析 1. CopyOnWriteArrayList 其中底层实现存放数据是一个Object数组: private volatile transie ... 
- mybatis源码分析(一)
			mybatis源码分析(sqlSessionFactory生成过程) 1. mybatis框架在现在各个IT公司的使用不用多说,这几天看了mybatis的一些源码,赶紧做个笔记. 2. 看源码从一个d ... 
- Design Patterns笔记
			一些笔记. strategy : facilitates the switch of the different but related algorithms/behaviors observer p ... 
- linux系统中,文件的三种特殊权限
			背景介绍 在linux系统中,我们熟知有rwx三种权限,对应所有者,同组用户,其他用户三种用户的权限,一共9个位来指定一个文件的权限情况,通过chmod xxx 来更改权限属性,其中xxx是已八进制表 ... 
- 分布式文件系统FastDFS详解
			上一篇文章<一次FastDFS并发问题的排查经历>介绍了一次生产排查并发问题的经历,可能有些人对FastDFS不是特别的了解,因此计划写几篇文章完整的介绍一下这个软件. 为什么要使用分布式 ... 
