1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <sstream> #include <string> #include <cstring> #include <cmath> #define ll long long using namespace std; ll digitCount[10]; ll pwr; ll numberOfDigit[15];//total count of i digit numbers int getLength(int a) { if(a<10) { pwr=1; return 1; } int len=0; pwr=1; while(a) { len+=1; a/=10; pwr*=10; } pwr/=10;//10 to the powr length-1; i.e for 3 digit number 10^2=100 return len; } int main() { int t,n,msd,length; ll totaldigit,leadingZeros,nonzeros; numberOfDigit[0]=0; numberOfDigit[1]=9;//there are 9 1'digit numbers, 90 2'digit numbers for(int i=2;i<15;i++) numberOfDigit[i]=numberOfDigit[i-1]*10; scanf("%d",&t); while(t--) { scanf("%d",&n); leadingZeros=0; nonzeros=0; for(int i=0;i<10;i++) digitCount[i]=0; length = getLength(n); for(int i=1;i<length;i++) { leadingZeros+= numberOfDigit[i]*(length-i); } totaldigit = length*n;//including leading and trailing zeros while(n) { msd = n/pwr; for(int i=1;i<10;i++) { digitCount[i]+= msd*(length-1)*(pwr/10);//N*10^(N-1) each digit, here N = length-1 and pwr/10 = 10^(N-1) } for(int i=1;i<msd;i++) digitCount[i]+=pwr; digitCount[msd]+=(n%pwr+1); n=n%pwr; pwr/=10; length-=1; } for(int i=1;i<10;i++) nonzeros+=digitCount[i]; digitCount[0] = totaldigit-leadingZeros-nonzeros; for(int i=0;i<10;i++) cout<<digitCount[i]<<(i!=9?" ":"\n"); } return 0; } |