Pagini recente » Cod sursa (job #931871) | Cod sursa (job #1256342) | Cod sursa (job #921456) | Cod sursa (job #703629) | Cod sursa (job #466680)
Cod sursa(job #466680)
#include <cstdio>
#define lmax 1000000
int a[lmax], b[lmax], r[lmax], c[12];
void produs()
{
int i, j, t, l;
for (i=1; i<=a[0]; i++)
{
t=0;
l=i-1;
for (j=1; j<=b[0]; j++)
{
l++;
r[l]+=b[j]*a[i]+t;
t=r[l]/10;
r[l]%=10;
}
while (t)
{
r[++l]=t%10;
t/=10;
}
if (l>r[0]) r[0]=l;
}
}
int main()
{
freopen("prod.in","r",stdin);
freopen("prod.out","w",stdout);
int i, s=0, k=0, aux;
for (i=1; i<=9; i++)
{
scanf("%d",&c[i]);
s+=c[i];
}
for (i=9; i>0; i--)
while (c[i])
{
k++;
if (k%2)
a[++a[0]]=i; else b[++b[0]]=i;
c[i]--;
}
if (s%2)
{
b[++b[0]]=a[a[0]];
a[0]--;
}
for (i=1; i<=a[0]/2; i++)
{
aux=a[i];
a[i]=a[a[0]-i+1];
a[a[0]-i+1]=aux;
}
for (i=1; i<=b[0]/2; i++)
{
aux=b[i];
b[i]=b[b[0]-i+1];
b[b[0]-i+1]=aux;
}
produs();
for (i=r[0]; i>0; i--) printf("%d",r[i]);
}