Cod sursa(job #1532906)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 21 noiembrie 2015 19:38:04
Problema Prod Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <cstdio>
#define MAXS 1000
#define MAX0 1000000
int fr[10], a[MAXS+1], b[MAXS+1], c[MAX0+3];
inline bool cmp(){
    if(a[0]!=b[0]){
        return a[0]<b[0];
    }
    int i=1;
    while((i<a[0])&&(a[i]==b[i])){
        i++;
    }
    return a[i]<b[i];
}
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=0; j<fr[i]; j++){
            if(cmp()){
                a[++a[0]]=i;
            }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;
}