标签:
11
1
4
1
1
1
1
1
1
1
1
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int b[10], c[10], f[10], m; void slove() { int M = m, n = 0; while(M > 0){ n++; M /= 10; } b[0] = 1; for(int i = 1; i <= 9; i++) { b[i] = 10 * b[i - 1]; } M = m; for(int i = 0; i < n; i++){ c[i] = M % 10; M = M / 10; } for(int i = 0; i <= 9 ; i++){ f[i] = 0; } for(int i = n-1; i >= 1; i--) { for(int k = 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(int k = 0; k <= 9; k++) { if (k <= c[0]) f[k] += 1; } for(int i = 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(int i = 0; i <= 9; i++){ printf("%d\n", f[i]); } } int main() { cin >> m; slove(); return 0; }
标签:
原文地址:http://www.cnblogs.com/cshg/p/5641830.html