Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int absolute_value(int a) {
- if(a < 0) {
- return -a;
- }
- else {
- return a;
- }
- }
- int min(int a, int b) {
- if(a < b) {
- return a;
- }
- else {
- return b;
- }
- }
- int main()
- {
- int a, b;
- cin >> a >> b;
- int cekori = 0;
- while(a > 0 and b > 0) {
- int cifra_a = a % 10;
- int cifra_b = b % 10;
- int prv_nacin = absolute_value(cifra_a - cifra_b);
- int vtor_nacin = 10 - cifra_a + cifra_b;
- int tret_nacin = 10 - cifra_b + cifra_a;
- int pomal_od_prv_i_vtor = min(prv_nacin, vtor_nacin);
- int najmal = min(pomal_od_prv_i_vtor, tret_nacin);
- cekori += najmal;
- a /= 10;
- b /= 10;
- }
- cout << cekori << endl;
- return 0;
- }
- // 5
- // 4 3 1 2 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement