Description given two positive integers a and B, for all integers in [a, b], how many times each digital (digit) appears. Only one line of two integers a, B, is included in the input file, meaning as described above. The output file contains a row of 10 integers representing the number of times that 0-9 appears in [A, b]. Sample Input1 99
Sample Output9 20 20 20 20 20 20 20 20 20
HINT
30% of the data in,a<=b<=10^6;
100% of the data, a<=b<=10^12.
/*make F[i] The number of occurrences of each number in the I-digit (the leading 0) (must be the same, so only one is recorded) there is f[i]=f[i-1]*10+10^ (i-1)*/#include<cstdio>#include<iostream>#defineLon Long Longusing namespaceStd;lon ans[ -],f[ -];voidResolve (Lon X,lon POS) { while(x) ans[x%Ten]+=pos,x/=Ten;}voidDP (Lon X,lon flag) {intI,j;lon Pos,now; for(i=1, pos=Ten;p os<x;i++,pos*=Ten){//"integer" section for(j=0; j<=9; j + +) Ans[j]+=f[i-1]*9*Flag; for(j=1; j<=9; j + +) Ans[j]+=pos/Ten*Flag; } Now=pos/=Ten; i--; while(now<x) {//The decimals Section while(now+pos<=x) {Lon temp=now/POS; Resolve (Temp,pos*flag); for(j=0; j<=9; j + +) Ans[j]+=f[i]*Flag; now+=POS; } POS/=Ten; i--; } }intMain () {Lon a,b,pos;inti; f[1]=1; for(i=2, pos=Ten; i<= A; i++,pos*=Ten) F[i]=f[i-1]*Ten+POS; CIN>>a>>b; DP (b+1,1);DP(a,-1);//differential for(intI=0; i<=9; i++) printf ("%lld%c", ans[i],i==9?'\ n':' '); return 0;}
Count number counts (Bzoj 1833)