HDU 1047 Integer Inquiry
2014-12-01 11:44
399 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047
Total Submission(s): 13352 Accepted Submission(s): 3354
Problem Description
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The final input line will contain a single zero on a line by itself.
Output
Your program should output the sum of the VeryLongIntegers given in the input.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input
Sample Output
大水题。
高精度加法,不存在发杂度的问题,也不用压位高精。
Integer Inquiry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13352 Accepted Submission(s): 3354
Problem Description
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The final input line will contain a single zero on a line by itself.
Output
Your program should output the sum of the VeryLongIntegers given in the input.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input
1 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
Sample Output
370370367037037036703703703670
大水题。
高精度加法,不存在发杂度的问题,也不用压位高精。
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<sstream> #include<vector> #include<map> #include<stack> #include<list> #include<set> #include<queue> #define LL long long #define lson l,m,rt<<1 #define rson m+1,r,rt<<1 | 1 using namespace std; const int maxn=1005,maxe=100005,inf=1<<29; int n,m; char a[maxn],b[maxn]; int na[maxn],nb[maxn]; void add() { int la=strlen(a),lb=strlen(b),lmax=max(la,lb); memset(na,0,sizeof(na)); memset(nb,0,sizeof(nb)); for(int i=0;a[i];i++) na[la-i-1]=a[i]-'0'; for(int i=0;b[i];i++) nb[lb-i-1]=b[i]-'0'; for(int i=0;i<lmax;i++) na[i]+=nb[i],na[i+1]+=na[i]/10,na[i]%=10; if(na[lmax]) lmax++; for(int i=0;i<lmax;i++) a[lmax-i-1]=na[i]+'0'; a[lmax]='\0'; } int main() { int t; scanf("%d",&t); for(int T=1;T<=t;T++) { if(T!=1) printf("\n"); scanf("%s",a); if(a[0]=='0') { printf("0\n"); continue; } while(scanf("%s",b)&&b[0]!='0') add(); printf("%s\n",a); } return 0; }
相关文章推荐
- HDU-1047 Integer Inquiry
- HDU-1047 Integer Inquiry Java
- hdu 1047 Integer Inquiry(高精度数)
- hdu 1047 Integer Inquiry(JAVA)
- hdu 1047 Integer Inquiry(高精度数)
- JAVA hdu 1047 Integer Inquiry(高精度)
- hdu 1047 Integer Inquiry
- HDU_1047 Integer Inquiry(高精度)
- HDU-1047-Integer Inquiry(Java大数水题 && 格式恶心)
- hdu 1047 Integer Inquiry(大数加)
- HDU 1047 Integer Inquiry
- HDU 1047 Integer Inquiry -- java大法好
- 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-1047-Integer Inquiry(Java大数水题 && 格式恶心)
- ZOJ 1292/HDU 1047 Integer Inquiry