Advertisement
Josif_tepe

Untitled

Feb 9th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int absolute(int broj) {
  6.     if(broj < 0) {
  7.         return broj * -1;
  8.     }
  9.     return broj;
  10. }
  11. int min(int broj1, int broj2) {
  12.     if(broj1 < broj2) {
  13.         return broj1;
  14.     }
  15.     return broj2;
  16. }
  17. int main()
  18. {
  19.     int p,k;
  20.     cin>>p>>k;
  21.     int a,b,c,d;
  22.     int x,y,z,l;
  23.     d=p%10;
  24.     c=(p/10)%10;
  25.     b=(p/100)%10;
  26.     a=(p/1000)%10;
  27.     l=k%10;
  28.     z=(k/10)%10;
  29.     y=(k/100)%10;
  30.     x=(k/1000)%10;
  31.     int zbir = 0;
  32.    
  33.     zbir += min(absolute(d - l), min(absolute(10 - d) + l, absolute(10 - l) + d));
  34.     zbir += min(absolute(c - z), min(absolute(10 - c) + z, absolute(10 - z) + c));
  35.     zbir += min(absolute(b - y), min(absolute(10 - b) + y, absolute(10 - y) + b));
  36.     zbir += min(absolute(a - x), min(absolute(10 - a) + x, absolute(10 - x) + a));
  37.     cout << zbir << endl;
  38.    
  39.    
  40. return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement