Test instructions: Gives N, writes the first n integers sequentially, and counts the number of occurrences of each number.
The stupidest way to do it--direct statistics--and later found that the online solution had to be done first.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 Chars[10005];8 inta[ the];9 Ten intMain () One { A intncase,n,i; -scanf"%d",&ncase); - while(ncase--) the { -scanf"%d",&n); -Memset (A,0,sizeof(a)); - for(i=1; i<=n;i++) + { - if(i<Ten) {a[i%Ten]++;} + if(i>=Ten&&i< -) {a[i/Ten]++;a[i%Ten]++;} A if(i>= -&&i< +) {a[i/ -]++;a[i/Ten%Ten]++;a[i%Ten]++;} at if(i>= +&&i<10000) {a[i/ +]++;a[i/ -%Ten]++;a[i/Ten%Ten]++;a[i%Ten]++;} - if(i>=10000) {a[i/10000]++;a[i/ +%Ten]++;a[i/ -%Ten]++;a[i/Ten%Ten]++;a[i%Ten]++;} - } - - for(i=0; i<=8; i++) -printf"%d", A[i]); inprintf"%d", A[i]); -printf"\ n"); to } + return 0; -}
View Code
UVa 1225 Digit Counting