Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- int p;
- int k;
- cin>>p>>k;
- int razlika=0;
- int razlika2=0;
- int najmalarazlika=0;
- int p1=p;
- int k1=k;
- vector<int>v(4);
- v[0]=p%10;
- p/=10;
- v[1]=p%10;
- p/=10;
- v[2]=p%10;
- p/=10;
- v[3]=p%10;
- vector<int>v1(4);
- v1[0]=k%10;
- k/=10;
- v1[1]=k%10;
- k/=10;
- v1[2]=k%10;
- k/=10;
- v1[3]=k%10;
- p=p1;
- k=k1;
- for(int y=0; y<4; y+=1){
- if(v[y]>v1[y]){
- razlika=v[y]-v1[y];
- razlika2=v1[y]+10-v[y];
- if(razlika<razlika2){
- najmalarazlika+=razlika;
- }
- else {
- najmalarazlika+=razlika2;
- }
- }
- if(v[y]<v1[y]){
- razlika=v1[y]-v[y];
- razlika2=v[y]+10-v1[y];
- if(razlika<razlika2){
- najmalarazlika+=razlika;
- }
- else {
- najmalarazlika+=razlika2;
- }
- }
- else{
- najmalarazlika+=0;
- }
- }
- cout<<najmalarazlika;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement