Cod sursa(job #227945)

Utilizator ProcopliucProcopliuc Adrian Procopliuc Data 5 decembrie 2008 22:46:23
Problema Next Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
# include <stdio.h>
int a[1000000],i,n,b[1000000],c[1000000],w,j,aux;
long long int x,z,y;
char q;
int nrcif (int x)
{
int k=0;
while (x)
{
k++;
x=x/10;
}
return k;

}



int main ()
{
freopen ("next.in","r",stdin);
freopen ("next.out","w",stdout);
i=0;
while (scanf ("%c",&q))
{

a[i]=q-48;
if (a[i]==-38)
break;
i++;
}
n=i;
scanf ("%lli",&x);
w=nrcif (x);
j=0;
j=j+w;
z=0;
for (i=0;i<j;i++)
y=y*10+a[i];
if (y<x)
{
y=y*10+a[j];
j++;
}
b[z]=y/x;
z++;
y=y%x;
while (j<n)
{
y=y*10+a[j];
j++;
b[z]=y/x;
z++;
y=y%x;
}
if (y==0)
{
for (i=0;i<n;i++)
printf ("%i",a[i]);

}



else
{
n=z;

i=n-1;
while (b[i]==9)
i--;
if (i==-1)
{
for (i=1;i<=n;i++)
b[i]=0;
n++;
b[0]=1;
}
else
{
b[i]++;
i++;

while (i<n)
{
b[i]=0;
i++;
}
}
for (i=0;i<n/2;i++)
{
aux=b[i];
b[i]=b[n-i-1];
b[n-i-1]=aux;
}
j=0;
while (x)
{
z=x%10;
x=x/10;

for (i=0;i<n+j;i++)
c[i+j]=b[i]*z;
j++;
}
n=n+j-1;

y=0;
for (i=0;i<n;i++)
{
b[i]=b[i]+y;
y=b[i]/10;
b[i]=b[i]%10;
}



while (y)
{
b[n]=y%10;
n++;
y=y/10;
}
for (i=n-1;i>=0;i--)
printf ("%i",c[i]);
}


return 0;
}