Time Limit: 2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i64u
Description
Scrooge McDuck keeps his is treasured savings in a home safe with a combination lock. Each time he wants into 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 have to turn some disks so, 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, on one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for?
Input
The first line contains a single integer n (1≤ n ≤1000)-the number of disks on the Combinati On 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 moves:
- 1 Disk:
- 2 Disk:
- 3 Disk:
- 4 Disk:
- 5 Disk:
Over Gotanda, water and water.
The AC code is attached:
1#include <iostream>2#include <cstring>3#include <cmath>4 using namespacestd;5 6 intN;7 Chara[1100],b[1100];8 intx[1100],y[1100];9 Ten intMain () { One while(cin>>N) { ACin>>a>>b; - for(intI=0; i<n;i++){ -x[i]=a[i]-'0'; they[i]=b[i]-'0'; - } - intsum=0; - for(intI=0; i<n;i++){ + if(ABS (X[i]-y[i]) >5) -sum+= (Ten-abs (x[i]-y[i])); + Else ASum+=abs (x[i]-y[i]); at } -cout<<sum<<Endl; - } - return 0; -}
A-combination Lock