这个题其实挺好的,一直在超时,后来用了数组去存就好了

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 const int MAXN = 300 ;
 4 int ch[MAXN] ;
 5 int main()
 6 {
 7     int i,j,n ;
 8     while(~scanf("%d",&n))
 9     {
10         for(int k = 0 ; k <= n ; k++)
11         {
12         memset(ch,0,sizeof(ch));
13         ch[0] = 1 ;
14             for(i = 2 ; i <= k ; i++)
15             {
16                 int c = 0 ;
17                 for(j = 0 ; j < MAXN ; j++)
18                 {
19                     int s = ch[j] * i + c ;
20                     ch[j] = s%10 ;
21                     c = s/10 ;
22                 }
23             }
24             for(j = MAXN - 1 ; j >= 0 ; j--)
25             {
26                 if(ch[j]) break ;
27             }
28             printf("%d! = ",k);
29             for(i = j ; i >= 0 ; i--)
30             {
31                 printf("%d",ch[i]) ;
32             }
33             printf("\n");
34         }
35         printf("\n") ;
36     }
37     return 0 ;
38 }

 

posted on 2013-04-19 21:16  枫、  阅读(314)  评论(0编辑  收藏  举报