Cod sursa(job #466791)

Utilizator antoanelaAntoanela Siminiuc antoanela Data 27 iunie 2010 14:51:29
Problema Prod Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, clasele X-XII, Ziua 1 Marime 1.36 kb
#include <cstdio>
#define lmax 10000

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[a[0]]=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;
    }
    /*for (i=a[0]; i>0; i--) printf("%d",a[i]);
    printf("\n");
    for (i=b[0]; i>0; i--) printf("%d",b[i]);
    printf("\n");*/
    produs();
    for (i=r[0]; i>0; i--) printf("%d",r[i]);
    printf("\n");
}