链接:https://www.nowcoder.net/acm/contest/75/E
来源:牛客网

时间限制:C/C++ 3秒,其他语言6秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
给定一个整数N(0≤N≤10000),求取N的阶乘
输入描述:
多个测试数据,每个测试数据输入一个数N
输出描述:
每组用一行输出N的阶乘
示例1
输入
1
2
3
输出
1
2
6

分析:用数组储存结果

#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <sstream>
#include <functional>
#include <algorithm>
using namespace std;

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define dec(i,n,a) for(int i=n;i>=a;i--)///[n,a]
#define pb push_back
#define fi first
#define se second
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MOD=258280327;
const int N=1e5+5;
const ll maxn=5e4;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
int ans[N];
int main()
{
    int h=1;///结果最高位
    int n;
    while(~scanf("%d",&n))
    {
        ans[0]=1;
        for(int i=1;i<=n;i++)
        {
            int c=0;///c为进位
            for(int j=0;j<h;j++)
            {
                int tmp=ans[j]*i+c;///计算结果
                ans[j]=tmp%10;///ans[j]为当前位
                c=tmp/10;///进位
            }
            while(c)
            {
                ans[h++]=c%10;///当前位;
                c/=10;///进位
            }
        }
        for(int i=h-1;i>=0;i--) printf("%d",ans[i]);
        puts("");
    }
    return 0;
}