Cod sursa(job #1532899)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 21 noiembrie 2015 19:20:15
Problema Prod Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <cstdio>
#define MAXS 1000
#define MAX0 1000000
int fr[10], a[MAXS+1], b[MAXS+1], c[MAX0+3];
int main(){
    int f, i, j, tr;
    FILE *fin, *fout;
    fin=fopen("prod.in", "r");
    fout=fopen("prod.out", "w");
    for(i=1; i<=9; i++){
        fscanf(fin, "%d", &fr[i]);
    }
    f=0;
    for(i=9; i>0; i--){
        for(j=2; j<fr[i]; j+=2){
            a[++a[0]]=i;
            b[++b[0]]=i;
        }
        if(fr[i]%2==1){
            if(a[0]<b[0]){
                a[++a[0]]=i;
            }else if(b[0]<a[0]){
                b[++b[0]]=i;
            }else if(f==0){
                a[++a[0]]=i;
                f=1;
            }else{
                b[++b[0]]=i;
            }
        }
    }
    for(i=a[0]; i>0; i--){
        for(j=b[0]; j>0; j--){
            c[a[0]-i+b[0]-j+1]+=a[i]*b[j];
        }
    }
    c[0]=a[0]+b[0]-1;
    tr=0;
    i=1;
    while((i<=c[0])||(tr>0)){
        tr+=c[i];
        c[i]=tr%10;
        tr/=10;
        i++;
    }
    i--;
    if(c[0]<i){
        c[0]=i;
    }
    for(i=c[0]; i>0; i--){
        fputc(c[i]+'0', fout);
    }
    fclose(fin);
    fclose(fout);
    return 0;
}