Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int A, B;
- cin >> A >> B;
- int res = 0;
- while(A > 0 and B > 0) {
- int cifra1 = A % 10;
- int cifra2 = B % 10;
- int plus = abs(cifra2 - cifra1);
- int minus = cifra1 + (10 - cifra2);
- int minus2 = (10 - cifra1) + cifra2;
- res += min(plus, min(minus, minus2));
- A /= 10;
- B /= 10;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment