zoukankan      html  css  js  c++  java
  • 大数相加模板

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cctype>
    #include <cmath>
    #include <algorithm>
    #include <numeric>
    #define maxn 101
    //char a[maxn],b[maxn],sum[maxn];
    using namespace std;
    string sum(string s1,string s2)
    {
        if(s1.length()<s2.length())
        {
            string temp=s1;
            s1=s2;
            s2=temp;
        }
        int i,j;
        for(i=s1.length()-1,j=s2.length()-1;i>=0;i--,j--)
        {
            s1[i]=char(s1[i]+(j>=0?s2[j]-'0':0));   //注意细节
            if(s1[i]-'0'>=10)
            {
                s1[i]=char((s1[i]-'0')%10+'0');
                if(i) s1[i-1]++;
                else s1='1'+s1;
            }
        }
        return s1;
    }
    int main()
    {
        string a,b;
        while(cin>>a>>b)
        {
            if(a[0]=='0'&&b[0]=='0') break;
            cout<<sum(a,b)<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    Tye exception
    DataSeeder
    angular
    认证Authentication
    MVC
    Ef Core
    工作单元
    VirtualFileSystem
    中间件
    日志
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7324136.html
Copyright © 2011-2022 走看看