Advertisement
Josif_tepe

Untitled

Oct 3rd, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.   int pocetok;
  7.   int kraj;
  8.   int cifra;
  9.   int cifra2;
  10.   int soplus;
  11.   int sominus;
  12.     int sominus2;
  13.   int zbir=0;
  14.   cin>>pocetok>>kraj;
  15.   while(kraj>0){
  16.     cifra=pocetok%10;
  17.     cifra2=kraj%10;
  18.     soplus=abs(cifra2-cifra);
  19.     sominus=abs(10-cifra+cifra2);
  20.       sominus2 = abs(10 - cifra2 + cifra);
  21.       if(sominus2 < sominus) {
  22.           sominus = sominus2;
  23.       }
  24.     if(soplus<sominus){
  25.         zbir+=soplus;
  26.     }
  27.     else zbir+=sominus;
  28.       pocetok/=10;
  29.     kraj/=10;
  30.  
  31.  
  32.   }
  33.   cout<<zbir<<endl;
  34.  return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement