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 ...
随机推荐
- LPCTSTR 字符串获取其长度
LPCTSTR lpStr = "123456789";int i=CString(lpStr).GetLength();
- win下配置qt creator 能够执行c/c++
首先需要相关包共四个: qt-win-opensource-4.8.5-mingw.exe qt-creator-windows-opensource-2.8.1.exe MinGW-gcc440_1 ...
- python3+beautifulSoup4.6抓取某网站小说(一)爬虫初探
本次学习重点: 1.使用urllib的request进行网页请求,获取当前url整版网页内容 2.对于多级抓取,先想好抓取思路,再动手 3.BeautifulSoup获取html网页中的指定内容 4. ...
- qrcode.js扫码邀请
//js引用部分<script src="../qrcode.js" type="text/javascript"></script> ...
- Node.js中的Buffer
Buffer介绍 为什么要用Buffer? 在Node/ES6 出现之前,前端工程师只需要进行一些简单的额字符串或者ODM操作就可以满足业务需求了,所有对二进制数据比较陌生. 在node出现之后,前端 ...
- PHP:车牌照合法性
文章来源:http://www.cnblogs.com/hello-tl/p/7592362.html <?php /** * [verifyCarCard description] 效验车牌号 ...
- python while、continue、break
while循环实现用户登录 _user = "tom" _passwd = "abc123" counter = 0 while counter < 3: ...
- 第十九节:Scrapy爬虫框架之Middleware文件详解
# -*- coding: utf-8 -*- # 在这里定义蜘蛛中间件的模型# Define here the models for your spider middleware## See doc ...
- 2017 GDCPC 省赛总结
第一年参加省赛,也是我接触acm半年多的第一个正式省级赛事,这半年来我为acm付出的可能很多,但经历过这次省赛后,给我唯一的感觉就是,还不够多. 直接分析题目吧,开始拿到试题后我读的是A题,然后我的队 ...
- GitHub总结
1) 工作原理 2) 工作流程 clone资源到本地 更新本地资源 新增或修改clone的资源 查看状态 资源推送回github