-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path1019.cpp
More file actions
50 lines (50 loc) · 925 Bytes
/
1019.cpp
File metadata and controls
50 lines (50 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
int cnt[10];
// prefix = 47, sz = 3 -> 47000~47999
// prefix = 5, sz = 2 -> 500~599
// prefix = 1, sz = 1 -> 10~19
// prefix = 42, sz = 0 -> 42~42
int pow10(int a) {
int t = 1;
while (a--) t *= 10;
return t;
}
void calc(int prefix, int sz) {
if (prefix == 0) {
if (sz == 0)
return;
for (int i = 0; i < 10; i++)
cnt[i] += sz * pow10(sz - 1);
for (int i = 1; i < sz; i++) {
cnt[0] -= 9 * pow10(sz - 1 - i)*i;
}
cnt[0] -= sz;
}
else{
while (prefix) {
cnt[prefix % 10] += pow10(sz);
prefix /= 10;
}
if (sz == 0)
return;
for (int i = 0; i < 10; i++)
cnt[i] += sz * pow10(sz - 1);
}
}
int main(void) {
int N;
scanf("%d", &N);
N++;
int now = 0;
while (now < N) {
for (int i = 0; ; i++) {
if (now + pow10(i) > N) {
calc(now / pow10(i - 1), i - 1);
now += pow10(i - 1);
break;
}
}
}
for (int i = 0; i < 10; i++)
printf("%d ", cnt[i]);
}