-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path324.cpp
More file actions
55 lines (52 loc) · 1.18 KB
/
324.cpp
File metadata and controls
55 lines (52 loc) · 1.18 KB
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
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
char a[1001][10000];
void swap(char b[10000]) {
int temp, i, j, l;
l = strlen(b);
for (i = 0, j = l - 1; i < l / 2; i++, j--) {
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
void work(char a[10000], char b[10000], int n) {
int i, j, onhand = 0, k, l;
l = strlen(a);
for (i = l - 1, j = 0; i >= 0; i--) {
k = ((a[i] - 48) * n) + onhand;
b[j] = (k % 10) + 48;
onhand = k / 10;
j++;
}
while (onhand > 0) {
b[j] = (onhand % 10) + 48;
onhand /= 10;
j++;
}
b[j] = '\0';
swap(b);
}
int main() {
int i, j, n, c[10];
strcpy(a[0], "1");
strcpy(a[1], "1");
for (i = 2; i <= 366; i++) {
work(a[i - 1], a[i], i);
}
while (scanf("%d", &n) == 1) {
if (n == 0) return 0;
memset(c, 0, sizeof(c));
for (i = 0; a[n][i] != '\0'; i++) {
j = a[n][i] - 48;
c[j]++;
}
printf("%d! --\n", n);
for (i = 0; i <= 9; i++) {
if (i == 5) printf("\n");
printf(" (%d)%5d", i, c[i]);
}
printf("\n");
}
return 0;
}