Josif_tepe

Untitled

Nov 20th, 2025
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int A, B;
  7.     cin >> A >> B;
  8.    
  9.     int res = 0;
  10.    
  11.     while(A > 0 and B > 0) {
  12.         int cifra1 = A % 10;
  13.         int cifra2 = B % 10;
  14.        
  15.         int plus = abs(cifra2 - cifra1);
  16.         int minus = cifra1 + (10 - cifra2);
  17.         int minus2 = (10 - cifra1) + cifra2;
  18.        
  19.         res += min(plus, min(minus, minus2));
  20.        
  21.        
  22.         A /= 10;
  23.         B /= 10;
  24.     }
  25.    
  26.     cout << res << endl;
  27.  
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment