#include<stdio.h> #include<string.h> int l1,l2,l3,l4,s1[410],s2[410],s3[410],s4[410],s5[420]; void div(char x[],int a[],int b[],int &d,int &e){ int l=strlen(x);d=e=0; while (x[d]!=‘.‘&&d<=l) d++; if (d<l){ for (int i=0;i<=d-1;i++) a[d-i]=x[i]-‘0‘; for (int i=d+1;i<l;i++) b[i-d-1]=x[i]-‘0‘; e=l-d-1; } else{ for (int i=0;i<l;i++) a[l-i]=x[i]-‘0‘; d=l; } } int cal(int n,int c){ int t; for (int i=1;i<=n;i++){ t=s1[i]+s3[i]+c; s1[i]=t%10; c=t/10; } if (c) {s1[n+1]=c;return n+1;}//ma else return n; } int calx(int n){ int t,c=0; for(int i=n-1;i>=0;i--){ t=s2[i]+s4[i]+c; s5[i]=t%10; c=t/10; } return c; } int main(){ char x[420],y[420]; int c; while(scanf("%s%s",x,y)!=EOF){ c=0; memset(s1,0,sizeof (s1)); memset(s2,0,sizeof (s2)); memset(s3,0,sizeof (s3)); memset(s4,0,sizeof (s4)); memset(s5,0,sizeof (s5)); div(x,s1,s2,l1,l2); div(y,s3,s4,l3,l4); if (l2>=l4) c=calx(l2); else c=calx(l4); if (l1>l3) l1=cal(l1,c); else l1=cal(l3,c); for (int i=l1;i>0;i--) printf("%d",s1[i]); int z=400; while (s5[z]<=0) z--; if (z>=0) { printf("."); for (int i=0;i<=z;i++) printf("%d",s5[i]); } printf("\n"); } return 1; }
1753
今天简直被字符串教做人了(╯‵□′)╯︵┻━┻
时间: 2024-11-05 02:36:39