-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path623.cpp
More file actions
42 lines (41 loc) · 890 Bytes
/
623.cpp
File metadata and controls
42 lines (41 loc) · 890 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
#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;
strcpy(a[0], "1");
strcpy(a[1], "1");
for (i = 2; i < 1001; i++) {
work(a[i - 1], a[i], i);
}
while (scanf("%d", &n) == 1) {
printf("%d!\n%s\n", n, a[n]);
}
return 0;
}