一个超时的写法:
c++大数阶乘+字符处理(逆序)
#include <bits/stdc++.h>
#define _MAX 100000000///计算1e5的阶乘
#define maxn 1e8
using namespace std;
int main()
{
int n, i, j, m;
long long a[10000], c;
while(scanf("%d",&n)!=EOF)
{
m = 0;
a[0] = 1;
for(i = 1; i <= n; i++)
{
c = 0;
for(j = 0; j <= m; j++)
{
a[j] = a[j] * i + c;
c = a[j] / _MAX;
a[j] %= _MAX;
}
if(c > 0)
{
m++;
a[m] = c;
}
}
int ans=0;
int j=-1;
for(int i=0;i<=m;++i)
{
if(a[i])
{
while(a[i]%10==0)
{
///cout<<"yes\n";
a[i]/=10;
}
cout<<a[i]%10<<endl;
break;
}
}
}
return 0;
}