HDU 1047 Integer Inquiry 大数相加 string解法
2017-05-25 19:50
495 查看
本题就是大数相加,题目都不用看了。
只是注意的就是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 1047 Integer Inquiry 多个大数相加
- HDU-1047 Integer Inquiry 大数相加
- HDU 1047 Integer Inquiry (多个大数相加)
- hdu 1047 Integer Inquiry(大数)
- HDU-1047-Integer Inquiry(Java大数水题 && 格式恶心)
- hdu acm-1047 Integer Inquiry(大数相加)
- BigNums——HDUOJ 1047 - Integer Inquiry(多个大数相加)
- hdoj 1047 Integer Inquiry 【多个大数相加】
- HDU - 1047 - Integer Inquiry (大数高精度)
- hdu 1047 Integer Inquiry 大数加法
- HDOJ 1047 Integer Inquiry(多个大数相加)
- HDU-1047-Integer Inquiry(Java大数水题 && 格式恶心)
- 杭电—1047 多个大数相加 Integer Inquiry
- Integer Inquiry_hdu_1047(大数).java
- HDU1047 - Integer Inquiry (大数加法)
- HDU 1047 Integer Inquiry JAVA大数
- HDU 1047 Integer Inquiry【大数】
- hdu 1047 Integer Inquiry(大数加)
- hdu 1047 Integer Inquiry