大数加法

本文介绍如何计算两个大整数A和B的和。通过输入输出示例展示算法的运用,帮助理解大数加法的过程。内容来源于网上资源。
摘要由CSDN通过智能技术生成

给出2个大整数A,B,计算A+B的结果。

Input

第1行:大数A
第2行:大数B
(A,B的长度 <= 10000 A B为正数)

Output

输出A + B

Input示例

68932147586
468711654886

Output示例

537643802472
#include<cstdio>
#include <cstring>
#include<iostream>
#include<cmath>
#include <stack>
using namespace std;
typedef long long LL;
int main()
{

    stack <int> a,b,c;
    char m[100000],n[100000];
    gets(m);

    gets(n);
    int la=strlen(m),lb=strlen(n);
    //printf("%d %d\n",la,lb);
    int i,j,k;
    for(i=0;i<la;i++)
    {
        char t=m[i]-48;
        a.push(t);
        //printf("%d ",t);
    }
    for(i=0;i<lb;i++)
    {
        char t=n[i]-48;
        b.push(t);
         //printf("%d ",t);
    }
    int e=0;
    for(;;)
    {
        int t,u,g=0;
        if(!a.empty())
        {
            t=a.top();
            a.pop();
        }

        else
         t=0;
        if(!b.empty())
        {
             u=b.top();
             b.pop();
        }
        else
         u=0;
        g=t+u+e;
        if(g>=10)
        {
            g=g%10;
       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值