Pagini recente » Cod sursa (job #992491) | Cod sursa (job #2108650) | Cod sursa (job #2658064) | Cod sursa (job #2786183) | Cod sursa (job #466934)
Cod sursa(job #466934)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 2010
int c[10];
int x[N],y[N],r[N];
inline void mul(int a[N],int b[N],int c[N])
{
memset(c,0,N*sizeof(int));
int i,j,t;
for(i=1; i<=a[0]; ++i)
{
t=0;
for(j=1; j<=b[0] || t; ++j,t/=10)
{
t+=c[i+j-1]+a[i]*b[j];
c[i+j-1]=t%10;
}
if(i+j-2>c[0])
c[0]=i+j-2;
}
}
inline void citire()
{
for(int i=1; i<=9; ++i)
scanf("%d",&c[i]);
}
inline void rezolva()
{
int j=0;
for(int i=9; i>0; --i)
{
for(; c[i]>0; --c[i])
{
if(x[0]<y[0])
{
x[++x[0]]=i;
continue;
}
if(y[0]<x[0])
{
y[++y[0]]=i;
continue;
}
if(x[j]==y[j])
++j;
if(x[j]<y[j])
x[++x[0]]=i;
else
y[++y[0]]=i;
}
}
for(int i=1,j=x[0]; i<j; ++i,--j)
swap(x[i],x[j]);
for(int i=1,j=y[0]; i<j; ++i,--j)
swap(y[i],y[j]);
mul(x,y,r);
for(int i=r[0]; i>0; --i)
printf("%d",r[i]);
printf("\n");
}
int main()
{
freopen("prod.in","r",stdin);
freopen("prod.out","w",stdout);
citire();
rezolva();
return 0;
}