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

只是注意的就是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. python 实现代理服务器

    # encoding:utf-8 import socket import thread import re def getAddr(d): a = re.search("Host: (.* ...

  2. 05EXtensible Stylesheet Language

    1. EXtensible Stylesheet Language 1. EXtensible Stylesheet Language XSL 指扩展样式表语言(EXtensible Styleshe ...

  3. 专题训练——[kuangbin带你飞]最短路练习

    最短路练习 0. Til the Cows Come Home  POJ - 2387 完美的模板题 //#include<Windows.h> #include<iostream& ...

  4. CSU 2018年12月月赛 B 2214: Sequence Magic

    Description 有一个1到N的自然数序列1,2,3,...,N-1,N. 我们对它进行M次操作,每次操作将其中连续的一段区间 [Ai,Bi][Ai,Bi] (即第Ai个元素到第Bi个元素之间的 ...

  5. MySQL主主配置及并行复制搭建

    思路: 两台机器互为主从. 机器1:192.168.1.160 机器2:192.168.1.164 修改两台机器的my.cnf文件,server-id,log-bin,auto-increment-i ...

  6. 修改 root密码

    sudo su #切换到root账户sudo passwd root  #输入密码

  7. Python之面向对象新式类和经典类

    Python之面向对象新式类和经典类 新式类和经典类的继承原理: 在Python3中,就只有新式类一种了. 先看Python3中新式类: 类是有继承顺序的: Python的类是可以继承多个类的,也就是 ...

  8. 第二周习题F

    Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multiplications: x2  ...

  9. 任务3.站会或DoD

    三选一 1.为开展敏捷团队:尝试一下引入站会 2.正在实践敏捷团队:定义DoD 3.从本次和上次学习中自己找出一个任务 <我们知道何时才算完成> <富有成效的每日站会> 目前所 ...

  10. 开启POP3/SMTP服务

    实现发送邮件时需要先启用POP3/SMTP服务(以qq邮箱和网易邮箱启用为例) 一 qq邮箱启用 二.网易邮箱开启POP3/SMTP服务 至此:服务已开启