hdu 1042 N!

来源:互联网 发布:上海税友有哪些软件 编辑:程序博客网 时间:2024/06/09 11:43
#include<iostream> 
#include<stdio.h>
 #include<string.h> 
using namespace std; 
const int  MAX=36900; 
int f[MAX];
int main()
 { 
 int n,i,s,j; 
 while(scanf("%d",&n)!=EOF
 { 
   memset(f,0,sizeof(f));
     f[0]=1; 
   int c=0,cnt=1;
   for(i=2;i<=n;i++)
  {
  for(j=0;j<cnt;j++)
 { 
   s=f[j]*i+c; 
   f[j]=s%10;
   c=s/10; 
 if(c>0&&j==cnt-1)
   {    cnt++;} 
 }
 } 
 for(i=cnt-1;i>=0;i--)
 {  cout<<f[i];} 
 cout<<endl
 } 
 return 0
}
0 0
原创粉丝点击