Advertisement
Guest User

958

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long p10(int y)
  6. {
  7.     long long p=1;
  8.     while(y>1)
  9.     {
  10.         p=p*10;
  11.         y--;
  12.     }
  13.     return p;
  14. }
  15.  
  16. int nrCif(long long n)
  17. {
  18.     int ncif=0;
  19.     while(n)
  20.     {
  21.         ncif++;
  22.         n=n/10;
  23.     }
  24.     return ncif;
  25. }
  26.  
  27. int main()
  28. {
  29.     long long n, nrcif, rez, m, sum, ci, i, v[11], p, pmax=0, j, pp, ps;
  30.     cin >> n;
  31.     m=n; n=n+1; nrcif=nrCif(n); rez=0; ci=90; i=1; ci=90; j=2;
  32.     for(i=1;i<=nrcif;i++)
  33.     {
  34.         if(i==1)
  35.             ci=10;
  36.         else if(i==2)
  37.                 ci=90;
  38.             else
  39.                 ci=ci*10;
  40.         if(i==nrcif)
  41.             rez=rez+i*abs(n-p10(i));
  42.         else
  43.         {
  44.             rez=rez+i*ci;
  45.             ci=ci*10;
  46.         }
  47.     }
  48.     for(i=1;i<=nrcif;i++)
  49.     {
  50.         v[i]=m%10;
  51.         cout << v[i] << " ";
  52.         m=m/10;
  53.     }
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement