Advertisement
Josif_tepe

Untitled

May 12th, 2024
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.     int broj1, broj2;
  7.     cin >> broj1 >> broj2;
  8.  
  9.     int a1 = broj1 % 10;
  10.     broj1 /= 10;
  11.     int a2 = broj1 % 10;
  12.     broj1 /= 10;
  13.     int a3 = broj1 % 10;
  14.     broj1 /= 10;
  15.     int a4 = broj1 % 10;
  16.     broj1 /= 10;
  17.  
  18.     int b1 = broj2 % 10;
  19.     broj2 /= 10;
  20.     int b2 = broj2 % 10;
  21.     broj2 /= 10;
  22.     int b3 = broj2 % 10;
  23.     broj2 /= 10;
  24.     int b4 = broj2 % 10;
  25.     broj2 /= 10;
  26.    
  27.     int res = 0;
  28.     int minus1 = min(10 - a1 + b1, 10 - b1 + a1);
  29.     int minus2 = min(10 - a2 + b2, 10 - b2 + a2);
  30.     int minus3 = min(10 - a3 + b3, 10 - b3 + a3);
  31.     int minus4 = min(10 - a4 + b4, 10 - b4 + a4);
  32.    
  33.     res += min(abs(b1 - a1), minus1);
  34.     res += min(abs(b2 - a2), minus2);
  35.     res += min(abs(b3 - a3), minus3);
  36.     res += min(abs(b4 - a4), minus4);
  37.  
  38.     cout << res << endl;
  39.    
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement