USACO3.21Factorials

枚举

 1 #include <iostream>
 2 /*
 3     ID: shangca2
 4     LANG: C++
 5     TASK: fact4
 6  */
 7 #include<cstdio>
 8 #include<cstring>
 9 #include<iostream>
10 
11 using namespace std;
12 int di[5000];
13 int main()
14 {
15     freopen("fact4.in","r",stdin);
16     freopen("fact4.out","w",stdout);
17     int i,j,k,n,g=0;
18     di[0] = 1;
19     cin>>n;
20     for(i = 1 ; i <= n ; i++)
21     {
22         for(j=0 ; j <= g ; j++)
23         di[j] *= i;
24         for(j = 0 ; j <= g ; j++)
25         {
26             if(di[j]>9)
27             {
28                 di[j+1] += di[j]/10;
29                 di[j] = di[j]%10;
30                 if(j+1>g)
31                 g = j+1;
32             }
33         }
34     }
35     k=0;
36     while(di[k]==0&&k<=g)
37     k++;
38     cout<<di[k]<<endl;
39     return 0;
40 }
View Code
原文地址:https://www.cnblogs.com/shangyu/p/3123136.html