本题就是大数相加,题目都不用看了。

只是注意的就是HDU的肯爹输出,好几次presentation error了。

还有个特殊情况,就是会有空数据的输入case。

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std; void plusABtoA(string &a, string &b)
{
string c;
int n = (int)a.size(), m = (int)b.size(), carry = 0;
for (int i = n-1, j = m-1; i >= 0 || j >= 0 || carry; i--, j--)
{
int an = i>=0? a[i]-'0' : 0;
int bn = j>=0? b[j]-'0' : 0;
carry = an+bn+carry;
c += char(carry%10 + '0');
carry /= 10;
}
reverse(c.begin(), c.end());
a = c;
} int main()
{
int N;
string a, b;
cin>>N;
while (N--)
{
cin>>a;
if (a == "0")//注意特殊情况
{
cout<<a<<endl;
if (N) cout<<endl;//注意肯爹输出<span style="white-space:pre"> </span>
continue;
}
while (cin>>b && b != "0")
{
plusABtoA(a, b);
}
cout<<a<<endl;
if (N) cout<<endl;//注意肯爹输出
}
return 0;
}

HDU 1047 Integer Inquiry 大数相加 string解法的更多相关文章

  1. hdu acm-1047 Integer Inquiry(大数相加)

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. hdu 1047 Integer Inquiry

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...

  3. POJ 1503 Integer Inquiry(大数相加)

    一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...

  4. POJ 1503 Integer Inquiry(大数相加,java)

    题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...

  5. hdu 1047 Integer Inquiry(大数)

    题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...

  6. hdu 1047 Integer Inquiry(高精度数)

    Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hi ...

  7. Integer Inquiry(大数相加)

    Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his explo ...

  8. HDU 1047 Integer Inquiry( 高精度加法水 )

    链接:传送门 思路:高精度水题 /************************************************************************* > File ...

  9. hdoj 1047 Integer Inquiry

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. CAD参数绘制椭圆(com接口)

    在CAD设计时,需要绘制椭圆,用户可以设置椭圆的基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipse 绘制椭圆.详细说明如下: 参数 说明 DOUBLE dCenterX 椭圆 ...

  2. java中属性命名get字母大小写问题

    java文件 company.java private int sTime; public void setSTime (int sTime) {        this.sTime = sTime; ...

  3. vue组件之this指向问题

    [问题描述] 返回顶部组件里,用到数据操作.通过方法里改动this数据,但发现直接使用失效 mounted() { window.onscroll=function(){ ) { this.isAct ...

  4. Mysql使用遇到的问题(一)

    1.在使用MySQL的时候,已经新建好了表,插入数据的时候报这个错误: Incorrect string value: '\xE5\xAF\x92\xE6\xB1\x9F...' for column ...

  5. g20学习笔记

    BALProblem.h---------定义BALProblem类. BALProblem类保存我们的BA所需要的所有数据,包括相机与路标之间的联系,相机变量+路标变量的初始值.这些数据的原始信息都 ...

  6. hdfs深入:06、hdfs的写入过程

    7.HDFS的文件写入过程 详细步骤解析: 1. client发起文件上传请求,通过RPC与NameNode建立通讯,NameNode检查目标文件是否已存在,父目录是否存在,返回是否可以上传: 2. ...

  7. bootstrap不兼容ie8如何解决

    说起bootstrap大家一定都不陌生,可以说是目前最受欢迎的前端框架,简洁.直观.强悍.移动设备优先的前端开发框架,让web开发更迅速.简单. 但是在实际运用中也会遇到各种各样的问题,比如最近项目中 ...

  8. tinyXml输出utf-8文档

    TiXmlDocument虽然能读取utf-8的xml文件,但读入后在内存中是以多字节存储.如果新建一个TiXmlDocument,即使定义头为utf-8编码,直接调用SaveFile方法保存的文档仍 ...

  9. NOIP2016玩具迷题

    题目大意就不说了,反正水水就过了. 主要在于找01关系. 代码: #include<cstdio> int n,m; struct node { ]; int f; }a[]; int m ...

  10. [Python3网络爬虫开发实战] 2.2-网页基础

    用浏览器访问网站时,页面各不相同,你有没有想过它为何会呈现这个样子呢?本节中,我们就来了解一下网页的基本组成.结构和节点等内容. 1. 网页的组成 网页可以分为三大部分——HTML.CSS和JavaS ...