Pagini recente » Cod sursa (job #887423) | Cod sursa (job #3268384) | Cod sursa (job #2345344) | Cod sursa (job #2233097) | Cod sursa (job #466954)
Cod sursa(job #466954)
# include <fstream>
# define DIM 1003
using namespace std;
int n, v[DIM], a[DIM], b[DIM];
ofstream fout ("prod.out");
void read ()
{
ifstream fin ("prod.in");
int x[12];
for(int i=1;i<=9;++i)
fin>>x[i];
for (int i=9;i;--i)
for(int j=1;j<=x[i];++j)
v[++n]=i;
}
int c[DIM];
void aduna ()
{
int q, t=0;
for(int i=1;i<=c[0];++i)
{
q=v[i]+c[i]+t;
v[i]=q%10;
t=q/10;
}
v[0]=c[0];
while (t)
{
q=t%10+v[++v[0]];
v[v[0]]=q%10;
t=q/10;
}
}
void inm ()
{
for(int i=1;i<=n;++i)
v[i]=0;
int q, t=0;
for(int i=1;i<=a[0];++i)
{
for(int j=1;j<2*b[0];++j)
c[j]=0;
c[0]=i-1;
for(int j=1;j<=b[0];++j)
{
q=a[i]*b[j]+t;
c[++c[0]]=q%10;
t=q/10;
}
while (t)
{
c[++c[0]]=t%10;
t/=10;
}
aduna ();
}
}
void solve ()
{
int i=1, x, y;
x=n/2;
y=x+n%2;
a[0]=x;b[0]=y;
while (v[i]==v[i+1] && i+1<=n)
{
a[x--]=v[i];
b[y--]=v[i+1];
i+=2;
}
if (i==n)
b[y--]=v[i-1];
else if (i+1<=n)
{
a[x--]=v[i];
b[y--]=v[i+1];
i+=2;
for(;i+1<=n;i+=2)
{
b[y--]=v[i];
a[x--]=v[i+1];
}
if (i==n)
b[y--]=v[i];
}
inm();
}
void afis ()
{
for(int i=v[0];i;--i)
fout<<v[i];
}
int main ()
{
read ();
solve ();
afis ();
return 0;
}