首页 > 其他 > 详细

大数加法(高精度加法)

时间:2020-03-15 00:48:03      阅读:83      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<cstring>
#include<cstdlib> 
using namespace std;

int main(){
    string s1,s2;
    cin>>s1>>s2;
    string maxx=s1,minn=s2;
    if(s1.size()<s2.length()){
        maxx=s2;
        minn=s1;
    }
    int a=maxx.length()-1,b=minn.length()-1;
    for(int i=b;i>=0;i--){
        maxx[a--]+=minn[i]-0;
    }

    for(int i=maxx.length()-1;i>0;i--){
        if(maxx[i]>9){
            maxx[i]-=10;
            maxx[i-1]++;
        }
    }
    if(maxx[0]>9){
        maxx[0]-=10;
        maxx="1"+maxx;
    }
    cout<<maxx;
    return 0;
}

 

大数加法(高精度加法)

原文:https://www.cnblogs.com/xwh-blogs/p/12495174.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!