zoukankan      html  css  js  c++  java
  • 32. 整数加法


     时间限制: 1 s

     空间限制: 128000 KB

     题目等级 : 白银 Silver

    题解

     查看运行结果

    题目描述 Description

    已知两个不超过200位的整数mn,求m+n的值。

    输入描述 Input Description

    输入mn。(中间有空格)

    输出描述 Output Description

    输出m+n的值。

    样例输入 Sample Input

    样例输入1

    123456789123456789 987654321

    样例输入2

    965758347 654235419

    样例输出 Sample Output

    样例输出1

    123456790111111110

    样例输出2

    1619993766

    数据范围及提示 Data Size & Hint

    输入整数不超过200位。

    代码:

    #include

    using namespace std;

    #include

    #include

    string m,n;

    int main()

    {

           int a[201],b[201],c[301]={0};

           cin>>m;

           cin>>n;

           a[0]=m.length();

           b[0]=n.length();

           for(int i=1;i<=a[0];++i)

                  a[i]=m[a[0]-i]-'0';

        for(int j=1;j<=b[0];++j)

            b[j]=n[b[0]-j]-'0';

     

           int i=1,x=0;

           while(i<=a[0]||i<=b[0])

           {

                  c[i]=a[i]+b[i]+x;

                  x=c[i]/10;

                  c[i]%=10;

                  ++i;

           }

           if(x!=0)

           c[i]=x;

           else i--;

           for(int j=i;j>=1;--j)

           printf("%d",c[j]);

          

           return 0; 

    }

  • 相关阅读:
    洛谷 P4297 [NOI2006]网络收费
    bzoj 5072: [Lydsy1710月赛]小A的树
    树形背包
    loj #2071. 「JSOI2016」最佳团体
    bzoj 2427: [HAOI2010]软件安装
    bzoj 4987: Tree
    loj #2007. 「SCOI2015」国旗计划
    loj #2006. 「SCOI2015」小凸玩矩阵
    loj #2020. 「AHOI / HNOI2017」礼物
    loj #547. 「LibreOJ β Round #7」匹配字符串
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290468.html
Copyright © 2011-2022 走看看