HDU 1047 Integer Inquiry 大数相加 string解法
本题就是大数相加,题目都不用看了。
只是注意的就是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解法的更多相关文章
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1047 Integer Inquiry
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
- hdu 1047 Integer Inquiry(大数)
题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...
- hdu 1047 Integer Inquiry(高精度数)
Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hi ...
- Integer Inquiry(大数相加)
Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his explo ...
- HDU 1047 Integer Inquiry( 高精度加法水 )
链接:传送门 思路:高精度水题 /************************************************************************* > File ...
- hdoj 1047 Integer Inquiry
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- lua 之 三木运算符
在c语言中我三目运算符这么写: a?b:c 例如: max = a>b?a:b; 在lua中我们这么写 max = a>b and a or b 运行如下:
- OpenCV2:应用篇 QT+OpenCV实现图片编辑器
一.简介 做完会放在Github上
- gprc-java与golang分别实现服务端,客户端,跨语言通信(一.java实现)
1.在pom中引入 <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty< ...
- Spring.Boot.1 -- 概览
Spring Boot 是如何简化Java 开发的 SpringBoot的一些重要特征 长久以来,Spring 框架作为Java应用开发的框架地位稳固.最近在云计算.大数据.无结构数据持续化.函数式反 ...
- vue 全局组件的注册
第一步 在main.js里面 引入需要注册的组件例如: //引入组件 import header from './components/header.vue' import footer from ...
- 安装php扩展(以swoole)为例
一.下载swoole到/usr/local/src目录下,操作 git clone https://gitee.com/swoole/swoole.git; 二.cd swoole,phpize(如果 ...
- CSS九宫格样式
CSS .main>div { width: 14%; min-width: 160px; padding: 2%; height: 60px; border: 1px solid #f4f4f ...
- Python之模块和包的创建与使用
一.模块的概念 在计算机的开发过程中,随着程序代码越写越多,在一个文件里代码就越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,放在不同的文件里面,这样,每个文件包含的代码就相对 ...
- vs2003 刷新项目失败。无法从服务器中检索文件夹信息
环境: 操作系统:windows server 2003 开发工具:Visual stuadio 2003 FrameWork: 1.1 打开web项目的时候报错 提示 项目刷新失败,无法从服务器 ...
- JDK的安装和环境变量配置
1.安装JDK开发环境 下载网站: http://www.oracle.com/technetwork/java/javase/downloads/index.html 进入后选择Accept Lic ...