#include<iostream>
#include<list>
#include<string>
using namespace std; int main()
{
list<int>l1, l2, l3;
string s1, s2;
cin >> s1;
cin >> s2; //储存大数
for (int i = 0; i<s1.length(); i++)
l1.push_front(s1[i] - '0'); for (int i = 0; i<s2.length(); i++)
l2.push_front(s2[i] - '0'); list<int>::iterator it1, it2;
it1 = l1.begin();
it2 = l2.begin(); //进位保存
int carry = 0; //计算位数相同部分
while (it1 != l1.end() && it2 != l2.end())
{
l3.push_front((*it1 + *it2 + carry) % 10);
carry = (*it1 + *it2 + carry) / 10;
it1++;
it2++;
} list<int>::iterator it3 = (it1 == l1.end()) ? it2 : it1;
list<int>::iterator it4 = (it1 == l1.end()) ? l2.end() : l1.end(); //计算位数不相同部分
while (it3 != it4)
{
l3.push_front((*it3 + carry) % 10);
carry = (*it3 + carry) / 10;
it3++;
}
l3.push_front(carry); //输出
for (list<int>::iterator it = l3.begin(); it != l3.end(); it++)
cout << *it;
cout << endl; return 0;
}

  

大数加法(STL list)的更多相关文章

  1. 51nod 1005 大数加法

    #include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...

  2. c#大数加法

    在C#中,我们经常需要表示整数.但是,c#的基本数据类型中,最大的long也只能表示-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807之间的数 ...

  3. 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)

    题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...

  4. Leetcode 67 Add Binary 大数加法+字符串处理

    题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...

  5. HDU1002大数加法

    大数加法 c++版: #include <map> #include <set> #include <stack> #include <queue> # ...

  6. java实现大数加法、乘法(BigDecimal)

    之前写过用vector.string实现大数加法,现在用java的BigDecimal类,代码简单很多.但是在online-judge上,java的代码运行时间和内存大得多. java大数加法:求a+ ...

  7. vector、string实现大数加法乘法

    理解 vector 是一个容器,是一个数据集,里边装了很多个元素.与数组最大的不同是 vector 可以动态增长. 用 vector 实现大数运算的关键是,以 string 的方式读入一个大数,然后将 ...

  8. 【大数加法】POJ-1503、NYOJ-103

    1503:Integer Inquiry 总时间限制:  1000ms 内存限制:  65536kB 描述 One of the first users of BIT's new supercompu ...

  9. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

  10. NI笔试——大数加法

    NI笔试: 1.找出字符串第一次出现的字符.用数组建立哈希表,然后再扫描字符串并判断次数是否为1. 2.大数加法,即字符串加法.因为之前写过乘法,就以为是乘法.然后就把乘法写上去了····= = 好了 ...

随机推荐

  1. input的placeholder字体大小无法修改?

    链接如下 其实chrome是有这个东西的,那就是shadow DOM. 什么是Shadow-Dom?Shadow DOM是指浏览器的一种能力,它允许在文档(document)渲染时插入一棵DOM元素子 ...

  2. jQuery基础教程第四版练习答案

    第二章 1. $('#selected-plays>li>ul>li').nextAll().addBack().addClass('special'); 2. $('table') ...

  3. CoreJavaE10V1P3.7 第3章 Java的基本编程结构-3.7 输入输出(Input ,Output)

    3.7.1 读取输入 Scanner in = new Scanner(System.in); System.out.print("What is your name? "); S ...

  4. CodeForces 710E Generate a String

    $SPFA$,优化,$dp$. 写了一个裸的$SPFA$,然后加了一点优化就过了,不过要$300$多$ms$. $dp$的话跑的就比较快了. $dp[i]$表示输入$i$个字符的最小花费. 首先$dp ...

  5. 凭借5G研究优势,诺基亚将携手菲律宾将其应用于VR/AR领域

    目前,很多人都在抱怨网速不行,影响视频的流畅播放,未来这些问题可以通过5G解决.近日,诺基亚和PLDT的全资子公司Smart首次在菲律宾一个"现场"网络演示上实现了5G速度,该网络 ...

  6. 安装配置Postgresql

    //关闭selinuxgetenforcesetenfroce 0vi /etc/selinux/configSELINUX=disabledSELINUXTYPE=targeted//关闭防火墙#c ...

  7. Hadoop之MapReduce分布式计算

    简单介绍一下项目背景——很简单,作死去接下老师的活,然后一干就是半个月,一直忙着从零基础到使用Hadoop中的MapReduce来解决一个实际问题,也就是用来计算一个数据量较大的二度朋友关系. 那么首 ...

  8. Gulp安装使用教程

    题记:为什么要使用gulp,网上有很多关于gulp的优势,而在我看来,这些都是工具的优势!工具的优势最主要体现在易用性上,听说gulp比grunt更易用,所以这里写个文档记录. 同样要保证nodejs ...

  9. ios 开发证书 appids 描述文件关系

    当你准备进行真机测试或者发布应用到App Store上去的时候, 免不了要申请相应的证书.(Development--测试证书. Distribution--发布证书) 进入证书管理相应网站https ...

  10. 使用inno setup制作安装包