Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("iepuras.in");
- ofstream fout("iepuras.out");
- int n, C;
- long long nr, nmax, nmin, aux, nrap, p;
- long long numar_mare(long long x)
- {
- int frm[10];
- for(int c=0; c<10; ++c)
- frm[c]=0;
- long long mare=0;
- do
- {
- frm[x%10]=1;
- x/=10;
- }while(x);
- for(int c=9; c>=0; --c)
- if(frm[c])
- mare=mare*10+c;
- return mare;
- }
- long long numar_mic(long long x)
- {
- int frc[10], ok=0;
- long long mic=0;
- for(int c=0; c<10; ++c)
- frc[c]=0;
- do
- {
- frc[x%10]=1;
- if(x%10==0)
- ok=1;
- x/=10;
- }while(x);
- if(ok)
- {
- int c=1;
- while(frc[c]==0)
- c++;
- mic=c;
- frc[c]=0;
- }
- for(int c=0; c<10; ++c)
- if(frc[c])
- {
- mic=mic*10+c;
- frc[c]=0;
- }
- return mic;
- }
- int main()
- {
- fin>>C;
- if(C==1)
- {
- fin>>n;
- for(int i=1; i<=n; ++i)
- {
- fin>>nr;
- nmax=numar_mare(nr);
- nmin=numar_mic(nr);
- fout<<(nmax+nmin)<<'\n';
- }
- return 0;
- }
- fin>>n;
- for(int i=1; i<=n; ++i)
- {
- fin>>nr;
- aux=nr;
- p=1;
- nrap=0;
- long long alt=0;
- int cifc=(aux%9==0 ? 9 : aux%9);
- do
- {
- if(cifc<(nr % 10)) nrap=nrap+((nr / 10)+1)*p;
- if (cifc>(nr % 10)) nrap=nrap+(nr / 10)*p;
- if (cifc==(nr % 10)) nrap=nrap+((nr / 10)*p)+alt+1;
- alt=alt+(nr % 10)*p;
- nr=nr / 10;
- p=p*10;
- } while(nr>0);
- fout<<nrap<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement