hbmy周赛1--E

E - Combination Lock

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

Submit Status

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: 
#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;
}
时间: 2024-11-07 04:08:33

hbmy周赛1--E的相关文章

hbmy周赛1--C

C - Exam Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects

hbmy周赛1--D

D - Toy Cars Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The proces

HLJU周赛5解题报告

Problem A: 求第K大数 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 81  Solved: 32 [Submit][Status][Web Board] [Edit] [TestData] Description 一天,喜欢看电影的DoubleQ 和 XXZ 来到一个神奇的电影院,这个电影院可以同时放映n部电影,每部电影都有相应的票价xi,面对着杀破狼2,侏罗纪世界,少年班等等好看的电影,他们最后商量,看票价第K大的电影,但是由于电影

CSDN 轻松周赛赛题:能否被8整除

轻松周赛赛题:能否被8整除 题目详情 给定一个非负整数,问能否重排它的全部数字,使得重排后的数能被8整除. 输入格式: 多组数据,每组数据是一个非负整数.非负整数的位数不超过10000位. 输出格式 每组数据输出一行,YES或者NO,表示能否重排它的全部数字得到能被8整除的数.注意: 重排可以让0开头. 答题说明 输入样例   610 122 输出样例   YES NO 解释   第一个数可以变为016 , 160 解题:很水的一道题...思路很简单,1000是能被8整除的,所以一千的倍数都能被

2015 年 JXNU_ACS 算法组寒假第二次周赛

2015 年 JXNU_ACS 算法组寒假第二次周赛 比赛链接:http://acm.hdu.edu.cn/diy/contest_show.php?cid=26246 Start Time : 2015-02-01 13:00:00 End Time : 2015-02-01 17:30:00 终榜:http://acm.hdu.edu.cn/diy/contest_ranklist.php?cid=26246&page=1 这次比赛考查的知识都很基础,甚至还有几道就是C语言基础(比如1006

周赛 POJ 2250 Compromise

Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe except for Luxembourg). To enforce that Germa

周赛 POJ 3934 Queue

Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning hall is a little bit far away from the classroom, those n kids have to walk in line to the dinning hall every day. When they are walking in line, if a

周赛 POJ 3546 The Dragon of Loowater

Description Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese populati

周赛 POJ 2245 Lotto

Description In the German Lotto you have to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k > 6) of these 49 numbers, and the