HDU 1002 A + B Problem II

HDU 1002 A + B Problem II
/*高精度*/
#include <cstdio> #include <iostream> using namespace std; const int modnum=10; int main() { int n; scanf("%d",&n); int m=n; while(n--) { printf("Case %d:\n",m-n); int a[1010]={0},b[1010]={0},c[1010]={0}; char ch1[1010],ch2[1010]; scanf("%s",&ch1); scanf("%s",&ch2); a[0]=strlen(ch1); for (int i=1; i<=a[0]; i++) a[i]=ch1[a[0]-i]-0; b[0]=strlen(ch2); for (int i=1; i<=b[0]; i++) b[i]=ch2[b[0]-i]-0; int x=0,i=0; c[0]=a[0]>b[0]?a[0]:b[0]; for (int i=1;i<=c[0];i++) c[i]=a[i]+b[i]; for (int i=1;i<=c[0];i++){ c[i+1]+=c[i]/modnum; c[i]%=modnum; } c[0]++; while ((c[0] > 1) && (c[c[0]] == 0)) c[0]--; for (int i=a[0]; i; i--) printf("%d",a[i]); printf(" + "); for (int i=b[0]; i; i--) printf("%d",b[i]); printf(" = "); for (int i=c[0]; i; i--) printf("%d",c[i]); printf("\n"); if (n) printf("\n"); } return 0; }
HDU 1002 A + B Problem II

HDU 1002 A + B Problem II

上一篇:轮询和长轮询


下一篇:smarty学习——变量