Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- long double n,ats,d=1,ch=1,sk0,sk1,sk2;
- long double aa,ab,ac,ad,ia,ib,ic,id,qa,qb,qc,qd;
- long long int rez;
- char mas[4],mas2[4];
- cin>>mas[0]>>mas[1]>>mas[2]>>mas[3]>>n;
- aa = mas[0] - '0';
- ab = mas[1] - '0';
- ac = mas[2] - '0';
- ad = mas[3] - '0';
- sk0=(aa*1000)+(ab*100)+(ac*10)+(ad);ats=sk0;
- if(n==ch){cout<<ats<<endl;return 0;}
- mn:
- mas2[0]=mas[0];mas2[1]=mas[1];mas2[2]=mas[2];mas2[3]=mas[3];
- //Nedidejancia tvarka (sk1)
- for(long long int i = 4 - 1; i >= 1; i--){
- for(long long int j = 0; j < i; j++)
- {
- if(mas[j] > mas[j+1])
- {
- int foo = mas[j];
- mas[j] = mas[j+1];
- mas[j+1] = foo;
- }
- }
- }
- ia = mas[0] - '0';
- ib = mas[1] - '0';
- ic = mas[2] - '0';
- id = mas[3] - '0';
- sk1=(ia*1000)+(ib*100)+(ic*10)+(id);
- //Nemazejancia tvarka (sk2)
- for(long long int i = 4 - 1; i >= 1; i--){
- for(long long int j = 0; j < i; j++)
- {
- if(mas2[j] < mas2[j+1])
- {
- int foo = mas2[j];
- mas2[j] = mas2[j+1];
- mas2[j+1] = foo;
- }
- }
- }
- qa = mas2[0] - '0';
- qb = mas2[1] - '0';
- qc = mas2[2] - '0';
- qd = mas2[3] - '0';
- sk2=(qa*1000)+(qb*100)+(qc*10)+(qd);
- //Isvedam atsakyma
- rez=sk2-sk1;
- mas[0]='0' + (rez/1000);
- mas[1]='0' + ((rez-((rez/1000)*1000))/100);
- mas[2]='0' + (((rez-((rez/1000)*1000))-(((rez-((rez/1000)*1000))/100)*100))/10);
- mas[3]='0' + (((rez-(rez/1000)*1000)-(((rez-((rez/1000)*1000))/100)*100))-((((rez-((rez/1000)*1000))-(((rez-((rez/1000)*1000))/100)*100))/10)*10));
- ats=rez;
- ch+=1;
- if(n==ch || ch>10000){cout<<setprecision(60)<<ats<<endl;return 0;}else{goto mn;}
- return 0;
- }
Add Comment
Please, Sign In to add comment