Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
高精度加法#include <stdio.h> void fun(int *arr1,int *arr2,int *arr3,int *arr4) { int i; for(i=0;i<1000;i++) arr4[i]=arr1[i]+arr2[i]+arr3[i]; for(i=0;i<1000;i++) if(arr4[i]>=10) { arr4[i+1]+=arr4[i]/10; arr4[i]%=10; } } void fun2(int *arr) { int i; for(i=0;i<1000;i++) if(arr[i]>=10) { arr[i+1]+=arr[i]/10; arr[i]%=10; } } int main() { int arr[101][1001]; int i,j; int a0,a1,a2; int flag; while(scanf("%d%d%d",&a0,&a1,&a2)!=EOF) { for(i=0;i<101;i++) for(j=0;j<1001;j++) arr[i][j]=0; flag=0; arr[0][0]=a0;arr[1][0]=a1;arr[2][0]=a2; fun2(arr[0]); fun2(arr[1]); fun2(arr[2]); for(i=3;i<=99;i++) fun(arr[i-3],arr[i-2],arr[i-1],arr[i]); for(i=1000;i>=0;i--) if(arr[99][i]!=0) { flag=1; break; } if(flag) { for(;i>=0;i--) printf("%d",arr[99][i]); printf("\n"); } else { printf("0\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator