Friday, 22 August 2014

Project Euler problem 13.Large Sum

main()
{
int n=5000;
int a[n];
int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int res[90000];
for(i=0;i<=89999;i++)
{
res[i]=0;
}
n=89999;
int reserve;
int counter;
for(i=49;i>=0;i--){reserve=i;
for(counter=1;counter<=100;counter++)
{
res[n]+=a[reserve];
reserve=reserve+50;
}
if(res[n]>9){res[n-1]+=(res[n]/10);res[n]=res[n]%10;}
n--;
}
for(i=0;i<90000;i++)
{
if(res[i]!=0){break;}
}
int ka;
for(ka=1;ka<=9;ka++)
{
printf("%d",res[i]);i++;
}
}

No comments:

Post a Comment