留个高精度的模板
(Code)
#include<cstdio>
#include<cstring>
using namespace std;
int n , a[5005] , b[5005] , c[5005];
inline void Mul()
{
while (c[0]) c[c[0]--] = 0;
for(register int i = 1; i <= a[0]; i++)
{
int g = 0;
for(register int j = 1; j <= b[0]; j++)
{
c[i + j - 1] += a[i] * b[j] + g;
g = c[i + j - 1] / 10;
c[i + j - 1] %= 10;
}
c[i + b[0]] += g;
}
c[0] = a[0] + b[0];
while (c[c[0]] == 0 && c[0] > 1) c[0]--;
for(register int i = 1; i <= c[0]; i++) a[i] = c[i];
a[0] = c[0];
}
int main()
{
char s[50];
a[a[0] = 1] = 1;
scanf("%d" , &n);
for(; n; n--)
{
scanf("%s" , s);
int len = strlen(s);
b[0] = 0;
for(register int i = len - 1; i >= 0; i--) b[++b[0]] = s[i] - '0';
Mul();
}
for(register int i = a[0]; i; i--) printf("%d" , a[i]);
}