Cod sursa(job #327597)

Utilizator GheorgheMihaiMihai Gheorghe GheorgheMihai Data 29 iunie 2009 15:55:02
Problema Sarpe Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<stdio.h>
#include<string.h>
int n;
int v[4096];

void read()
{
	freopen("sarpe.in","r",stdin);
	freopen("sarpe.out","w",stdout);
	char s[1024];
	gets(s+1);
	n=strlen(s+1);
	int i,aux;
	for(i=1;i<=n;i++)
	{
		aux=s[i]-'0';
		v[i]=v[n-i+1]-'0';
		v[n-i+1]=aux;
	}
}

void mul()
{
	int i,j,t,c[4096];
	memset(c,0,sizeof(c));
	for(i=1;i<=n;i++)
	{
		for(t=0,j=1;j<=n||t;j++,t/=10)
			c[i+j-1]=(t+=c[i+j-1]+v[i]*v[j])%10;
		if(i+j-2>c[0]) 
			c[0]=i+j-2;
	}
	for(i=1;i<=c[0]||i<=n||t;i++,t/=10)
		c[i]=(t+=c[i]+v[i])%10;
	c[0]=i-1;
	c[1]+=2;
	for(i=c[0];i>=1;i--)
		printf("%d",c[i]);
}

int main()
{
	read();
	mul();
	return 0;
}