高精度(大整数加法)
2010-07-15 16:01
316 查看
]#include<iostream> #include<memory> using namespace std; const int max_len=200; int an1[max_len+10]; int an2[max_len+10]; char sz1[max_len+10]; char sz2[max_len+10]; int main() { int n,k; cin>>n; for(k=0;k<n;k++) { cin>>sz1>>sz2; //scanf("%s",sz1); //scanf("%s",sz2); int i,j; memset(an1,0,sizeof(an1)); memset(an2,0,sizeof(an2)); //------------------------------- int nlen1=strlen(sz1); j=0; for(i=nlen1-1;i>=0;i--) { an1[j++]=sz1[i]-'0'; } int nlen2=strlen(sz2); j=0; for(i=nlen2-1;i>=0;i--) { an2[j++]=sz2[i]-'0'; } //------------------------------- for(i=0;i<max_len;i++) { an1[i]+=an2[i]; if(an1[i]>=10) { an1[i]-=10; an1[i+1]++; } } //-------------------------------- bool b=false; for(i=max_len;i>=0;i--) { if(b) { printf("%d",an1[i]); } else if(an1[i]) { printf("%d",an1[i]); b=true; } } if(!b) { cout<<'0'; } cout<<endl; } return 0; }
相关文章推荐
- 任意长度的高精度大整数加法
- 【华为机试】无线OSS-高精度整数加法
- 任意长度的高精度大整数和浮点数的加法和乘法
- HDOJ1002 A+B Problem II(高精度/大整数加法)
- poj 1503 大整数高精度 加法
- 大整数加法(高精度)
- 高精度大整数加法
- 华为OJ------高精度整数加法
- 高精度 大整数加法
- 高精度整数加法
- [编程题]无线OSS-高精度整数加法
- uva 424(Integer Inquiry)高精度大整数加法
- POJ 1503(高精度整数加法) 解题报告
- 华为上机题:高精度整数加法
- 高精度整数加法
- 九度OJ-1198:a+b (高精度整数加法)
- POJ 1504 Adding Reversed Numbers (水题,高精度整数加法)
- 2010年华为上机笔试二(高精度整数加法)
- 无线OSS-高精度整数加法(加数可以为负数,应实现高精度加减法)
- POJ 1503(高精度整数加法) 解题报告