HDU 1047 Integer Inquiry 大数相加 string解法
来源:互联网 发布:java迭代器的使用 编辑:程序博客网 时间:2024/06/07 20:26
本题就是大数相加,题目都不用看了。
不过注意的就是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;}
1 1
- HDU 1047 Integer Inquiry 大数相加 string解法
- HDU-1047 Integer Inquiry 大数相加
- HDU ACM 1047 Integer Inquiry->大数相加
- HDU 1047 Integer Inquiry 多个大数相加
- HDU 1047 Integer Inquiry (多个大数相加)
- Integer Inquiry 大数相加
- Integer Inquiry(大数相加)
- Integer Inquiry 大数相加
- HDOJ 1047 Integer Inquiry(多次大数相加)
- HDU 1047--Integer Inquiry 【大数】
- HDU 1047 Integer Inquiry【大数】
- hdu 1047 Integer Inquiry(大数加)
- HDU - 1047 - Integer Inquiry (大数高精度)
- HDU 1047 Integer Inquiry JAVA大数
- hdu 1047 Integer Inquiry 大数加法
- HDU 1047Integer Inquiry(简单大数)
- hdoj 1047 Integer Inquiry 【多个大数相加】
- 杭电—1047 多个大数相加 Integer Inquiry
- lightoj 1240 计算机图论(计算三维点到线段的距离)
- SSH启动异常: java.lang.NoClassDefFoundError: javax/el/ExpressionFactory
- lombok配置问题
- instanceof
- The difference between register(寄存器), latch(锁存器) and flip-flop(触发器)
- HDU 1047 Integer Inquiry 大数相加 string解法
- http://www.doudoutxt.com/files/article/51465/728de201.html
- http://www.doudoutxt.com/files/article/51465/759z992.html
- List 的排序,重载greater<>实现
- 黑马程序员21——交通灯管理系统
- 冒泡法排序(汇编语言)
- http://www.doudoutxt.com/files/article/51465/281rs374.html
- ZOJ-3768
- http://www.doudoutxt.com/files/article/51465/632kl918.html