Cod sursa(job #1571628)

Utilizator CM_PunkEftime Andrei Horatiu CM_Punk Data 18 ianuarie 2016 11:26:41
Problema Prod Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("prod.in");
ofstream out("prod.out");
 
const int nmax = 10007;
int poz[10], a[nmax], b[nmax], c[nmax];
 
void inmultire(){
    int minte = 0;
    c[0] = a[0] + b[0] - 1;

    for(int i = 1; i <= a[0]; ++i)
        for(int j = 1; j <= b[0]; ++j)
            c[i + j - 1] += a[i] * b[j];

    for(int i = 1; i <= c[0]; ++i){
        minte = (c[i] += minte) / 10;
        c[i] %= 10;
    }

    if (minte)
        c[++c[0]] = minte;
}

int compar(){
    if (a[0]>b[0])
        return 1;
    else
        if(a[0]<b[0])
            return -1;

    for(int i = 1; i<=a[0]; i++)
        if(a[i]>b[i])
            return 1;
        else
            if(a[i]<b[i])
                return -1;
    return 0;
}
 
int main(){
    int player_unu=0;

    for(int i = 1; i <= 9; i++)
        in>>poz[i];

    for(int i = 9; i>=1; i--)
	{
        while (poz[i]>0)
		{
            if(compar()<0)
                a[++a[0]] = i;
            else
                b[++b[0]] = i;

            poz[i]--;
        }
    }

    reverse(a + 1, a + 1 + a[0]);
    reverse(b + 1, b + 1 + b[0]);

    inmultire();

    for(int i = c[0]; i>=1; i--)
        out<<c[i];
	out<<'\n';

    return player_unu;
}