UVa 1225
The main idea: to write the first n (n<=10000) integers together, 12345678910111213 ..., the number of a number 0-9 each occurrence of how many words
Problem-solving ideas: Using a CNT array to record 0-9 of the number of occurrences of the 10, first to initialize CNT to 0, and then let I from 1 to enumerate to N,
For each I, the number of each position that is treated with live I, and the corresponding CNT subscript on +1
The final output of the CNT array can
/*UVa 1225 Digit Counting---water problem*/#include<cstdio>#include<cstring>intcnt[ the];//Cnt[i] Record number I occurrences//get the number on each bit of n, and in the corresponding cnt+1voidFunintN) { if(n = =0){ return; } ++cnt[n%Ten]; Fun (n/Ten);}intMain () {intT, N; scanf ("%d", &t); while(t--) {scanf ("%d", &N); memset (CNT,0,sizeofCNT); for(inti =1; I <= N; ++i) {Fun (i); } for(inti =0; I <=9; ++i) {printf (i==9?"%d\n":"%d", Cnt[i]); } }//While (t) return 0;}
View Code
UVa 1225 Digit Counting---water problem