Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int absolute(int broj) {
- if(broj < 0) {
- return broj * -1;
- }
- return broj;
- }
- int min(int broj1, int broj2) {
- if(broj1 < broj2) {
- return broj1;
- }
- return broj2;
- }
- int main()
- {
- int p,k;
- cin>>p>>k;
- int a,b,c,d;
- int x,y,z,l;
- d=p%10;
- c=(p/10)%10;
- b=(p/100)%10;
- a=(p/1000)%10;
- l=k%10;
- z=(k/10)%10;
- y=(k/100)%10;
- x=(k/1000)%10;
- int zbir = 0;
- zbir += min(absolute(d - l), min(absolute(10 - d) + l, absolute(10 - l) + d));
- zbir += min(absolute(c - z), min(absolute(10 - c) + z, absolute(10 - z) + c));
- zbir += min(absolute(b - y), min(absolute(10 - b) + y, absolute(10 - y) + b));
- zbir += min(absolute(a - x), min(absolute(10 - a) + x, absolute(10 - x) + a));
- cout << zbir << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement