Pagini recente » Cod sursa (job #248651) | Cod sursa (job #2981482) | Cod sursa (job #1326999) | Cod sursa (job #2929390) | Cod sursa (job #501492)
Cod sursa(job #501492)
#include<fstream.h>
long i, aux, a[10],x[1001],y[1001],j,c[2002];
int compar()
{
long i;
if (x[0] > y[0]) return 1;
else if (x[0] < y[0]) return 0;
else
{
for (i=1;i<=x[0];i++)
if (x[i]>y[i]) return 1;
else if (x[i]<y[i]) return 0;
}
return 0;
}
void imultire()
{
long i,j;
for (i = 1;i<=x[0];i++)
for (j = 1;j<=y[0];j++)
{
if (i-j+1!=1)
{c[j-i+1] = x[i]*y[j]+c[j-i]/10;
c[j-i] %= 10;}
else {c[j-i+1] = x[i]*y[j];}
}
c[0] = j-i+1;
if (c[c[0]]>9)
{
c[c[0]+1] = c[c[0]]/10;
c[c[0]]%=10;
c[0]++;
}
}
int main()
{
ifstream f("prod.in");
ofstream g("prod.out");
for (i=1;i<=9;i++)
f>>a[i];
for (i=9;i>=5;i--)
{
aux = a[i];
a[i] = a[10-i];
a[10-i] = aux;
}
for (i=1;i<=9;i++)
{
for (j=1;j<=a[i];j++)
{
if (compar()==0)
{
x[++x[0]] = 10-i;
}
else
{
y[++y[0]] = 10-i;
}
}
}
if (x[0]!=1)
for (i=1;i>=x[0]/2;i--)
{
aux = x[i];
x[i] = x[x[0]+1-i];
x[x[0]+1-i] = aux;
}
if (y[0]!=1)
for (i=1;i>=y[0]/2;i--)
{
aux = y[i];
y[i] = y[y[0]+1-i];
y[y[0]+1-i] = aux;
}
imultire();
for (i=c[0];i>=1;i--)
g<<c[i];
g<<'\n';
g.close();
return 0;
}