HDOJ HDU 1047 Integer Inquiry
来源:互联网 发布:java sdk是什么 编辑:程序博客网 时间:2024/05/16 17:51
HDOJ 1047 Integer Inquiry
题目
点此查看 HDOJ 1047 Integer Inquiry
分类
大数 求和
题意
求 n 个数的 和 (n <= 100)
和 HDOJ 1002 Sum Problem 一样直接套用 字符相加函数 即可
代码
#include <iostream>#include <string>using namespace std;string add(string & a,string & b);int main(){ int t; string s1,s2; cin >> t; while(t--) { cin >> s1; if(s1 == "0") cout << '0' << endl; else{ while(cin >> s2) { if(s2 == "0") break; s1 = add(s1,s2); } cout << s1 << endl; } if(t) cout << endl; } return 0;}string add(string & a,string & b){// cout << a << endl << b << endl; string s; int t,c = 0; if(a.length() < b.length()) swap(a,b); for(int i = b.length();i < a.length();i++) b.insert(0,"0"); for(int i = 0;i < a.length();i++) s += '0'; for(int i = a.length()-1;i >= 0;i--) { t = (a[i] - '0') + (b[i] - '0') + c; s[i] = t % 10 + '0'; c = t / 10; } if(c) { string a; a += ('0' + c); s.insert(0,a); }// cout << s << endl; return s;}
阅读全文
0 0
- HDOJ HDU 1047 Integer Inquiry
- HDOJ 1047 Integer Inquiry
- HDOJ 1047 Integer Inquiry
- HDOJ 1047 Integer Inquiry
- hdoj 1047 Integer Inquiry
- hdoj 1047 Integer Inquiry
- Integer Inquiry hdoj 1047
- hdoj 1047 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
- hdu 1047 Integer Inquiry
- hdu-1047Integer Inquiry
- hdu 1047 Integer Inquiry
- HDU 1047 Integer Inquiry
- Android高级进阶-换肤
- 数据结构(Java)---线性表
- HDU 3631 Shortest Path Floyd
- Gan与imitation learning,theano平台搭建 (2)
- 235/236. Lowest Common Ancestor of a Binary Search Tree/Lowest Common Ancestor of a Binary Tree
- HDOJ HDU 1047 Integer Inquiry
- JAVA工具类(8) --- json转换工具类(对象与json转换)
- java &&和&,||和|
- codeforces 822A I'm bored with life
- Easypack:安全防护工具之:ClamAV之一键安装
- 对象成员及初始化列表的使用demo
- iOS调用系统相册显示英文
- 基于VLC框架的Android视频播放器Demo
- 【python学习笔记】Python自带特殊方法一览