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

只是注意的就是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. Hadoop推测执行机制问题

    问题描述:MultipleOutputs使用时hdfs报错         // :: INFO mapreduce.Job: Task Id : attempt_1525336138932_1106 ...

  2. java正则表达式进阶运用20181023

    直接上代码. package org.jimmy.autotranslate20181022.test; import java.util.regex.Matcher; import java.uti ...

  3. 散列的键值对没初始化时不要用print打印此值,不要用 . 操作符去连接打印 这个值。

    31 delete $vertical_alignment{$anonymous};     32 print $vertical_alignment{$anonymous}."\n&quo ...

  4. 执行jar包报错:udfFull.jar中没有主清单属性

    在windows系统的cmd命令行窗口中执行: java -jar udfFull.jar {"movie":"1287","rate":& ...

  5. <Spring Cloud>入门一 Eureka Server

    1.搭建父工程 主要是添加版本依赖,此处版本是: spring-boot  : 2.0.8.RELEASE spring-cloud : Finchley.SR2 <?xml version=& ...

  6. Ztree勾选节点后取消勾选其父子节点

    前言: Ztree官方给的API可以设置勾选一个节点的同时勾选子节点或者父节点,也可以设置不影响父子节点,即将chkboxType设置为{"Y":"",&quo ...

  7. Unix网络编程 — 头文件解析

    1.1. < sys/types.h > primitive system data types(包含很多类型重定义,如pid_t.int8_t等) 1.2. < sys/socke ...

  8. 九度oj 题目1063:整数和

    题目1063:整数和 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4043 解决:2638 题目描述: 编写程序,读入一个整数N.若N为非负数,则计算N到2N之间的整数和:若N为一个负数 ...

  9. 解决在使用Amoeba遇到的问题

    最近有同行在使用Amoeba 的过程中多少遇到了一些问题. 总结一下遇到问题的解决方法: 1.读写分离的时候设置的在queryRouter中设置无效? 读写分离配置的优先级别:        1)满足 ...

  10. MT6753/MT6755 呼吸灯功能添加

    利用mtk pmic自带的呼吸灯模式: 主要修改代码: kernel-3.10/drivers/misc/mediatek/leds/mt6755/leds.c   int mt_brightness ...