-
Notifications
You must be signed in to change notification settings - Fork 0
/
1042_1.c
50 lines (42 loc) · 1.13 KB
/
1042_1.c
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>
#include <string.h>
#define MAX_NUM 50000
int main(int argc,char *argv[])
{
int i,j,N,cnt = 1,plus_one_flag,num;
char temp[MAX_NUM];
while(scanf("%d",&N) != EOF && N >= 0 && N <= 10000)
{
memset(temp,'0',sizeof(temp)); //memset(temp,0,sizeof(temp));
temp[MAX_NUM - 1] = '1';
cnt = 1;
for(i = 2;i <= N;i++)
{
plus_one_flag = 0;
for(j = 1;j <= cnt;j++)
{
num = i * (temp[MAX_NUM - j] - '0') + plus_one_flag;
if(num / 10 >= 1)
{
plus_one_flag = num / 10;
temp[MAX_NUM - j] = num % 10 + '0';
if(j == cnt)
{
++cnt;
}
}
else
{
temp[MAX_NUM - j] = num + '0';
plus_one_flag = 0;
}
}
}
for(i = MAX_NUM - cnt;i < MAX_NUM;i++)
{
printf("%c",temp[i]);
}
printf("\n");
}
return 0;
}