Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- int main()
- {
- int pocetok;
- int kraj;
- int cifra;
- int cifra2;
- int soplus;
- int sominus;
- int sominus2;
- int zbir=0;
- cin>>pocetok>>kraj;
- while(kraj>0){
- cifra=pocetok%10;
- cifra2=kraj%10;
- soplus=abs(cifra2-cifra);
- sominus=abs(10-cifra+cifra2);
- sominus2 = abs(10 - cifra2 + cifra);
- if(sominus2 < sominus) {
- sominus = sominus2;
- }
- if(soplus<sominus){
- zbir+=soplus;
- }
- else zbir+=sominus;
- pocetok/=10;
- kraj/=10;
- }
- cout<<zbir<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement