Question F: "Recursion and recursion" counter Title Descriptionthe number of pages in a book is n, and the page numbering starts from 1, please find out how many 0,1,2,...,9 are used in all the pages. Where-the page number does not contain extra 0, such as n=1234 when the 5th page is not 0005, just 5. Inputa positive integer N (n≤109) that represents the total page number. OutputTotal 10 lines: The number of K Act number k-1. Sample input
11
Sample output
1411111111
#include <iostream>#include<cstring>#include<cstdio>#include<cmath>using namespacestd;intb[Ten], c[Ten], f[Ten], M;voidSlove () {intm = m, n =0; while(M >0) {n++; M/=Ten; } b[0] =1; for(inti =1; I <=9; i++) {B[i]=Ten* B[i-1]; } M=m; for(inti =0; I < n; i++) {C[i]= M%Ten; M= M/Ten; } for(inti =0; I <=9; i++) {F[i]=0; } for(inti = n1; I >=1; i--) { for(intK =0; K <=9; k++) {F[k]+ = b[i-1]*i*C[i]; if(K < c[i]) F[k] + =B[i]; if(C[i] = = k) F[k] + + m% b[i] +1; } } for(intK =0; K <=9; k++) { if(k <= c[0]) F[k] + =1; } for(inti =0; I < n; i++) {f[0] -=B[i]; }//for (int i = n-1; I >= 1; i--) {//for (int k = 0; k <= 9; k++)//F[k] + = n% b[i];// } for(inti =0; I <=9; i++) {printf ("%d\n", F[i]); } }intMain () {CIN>>m; Slove (); return 0;}
View Code
Recursive and recursive counters