Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int br, i, temp, tempc, brc, brrk, min, fakebool=1, raz;
- cin>>br>>brrk;
- int zafateni[10];
- for(i=0;i<brrk;i++)
- {
- cin>>zafateni[i];
- }
- min=br-100;
- for(temp=br;temp<10000000;temp++)
- {
- fakebool=1;
- for (tempc=temp; fakebool==1;tempc/=10)
- {
- if(tempc==0) break;
- for(i=0;i<brrk;i++)
- {
- if(zafateni[i]==tempc%10){ fakebool=0; break; }
- }
- }
- if (fakebool==1) break;
- }
- raz=(temp-br);
- for(brc=0;temp;temp/=10)brc++;
- if (brc+raz<min)min=(brc+raz);
- for(temp=br;temp>0;temp--)
- {
- fakebool=1;
- for (tempc=temp; fakebool==1;tempc/=10)
- {
- if(tempc==0) break;
- for(i=0;i<brrk;i++)
- {
- if(zafateni[i]==tempc%10){ fakebool=0; break;}
- }
- }
- if (fakebool==1) break;
- }
- raz=(br-temp);
- for(brc=0;temp;temp/=10) brc++;
- if(brc+raz<min)min=(brc+raz);
- cout<<min;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement