POJ 1503 -- Integer Inquiry
Posted Amysear
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 1503 -- Integer Inquiry相关的知识,希望对你有一定的参考价值。
Integer Inquiry
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 35353 | Accepted: 13781 |
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.)
``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.
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.
Sample Input
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
Sample Output
370370367037037036703703703670
Source
几个大数相加= =
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 char a[101],BigInt[103]; 5 int main() 6 { 7 memset(BigInt,0,sizeof(BigInt)); 8 int L=0; 9 while(true) 10 { 11 memset(a,0,sizeof(a)); 12 cin>>a; 13 if(strcmp(a,"0")==0) 14 { 15 for(int j=L-1;j>=0;j--) 16 { 17 cout<<int(BigInt[j]); 18 } 19 cout<<endl; 20 break; 21 } 22 int aLen = strlen(a); 23 int BigJ = 0; 24 for(int j=aLen-1;j>=0;j--) 25 { 26 BigInt[BigJ++] += a[j]-\'0\'; 27 } 28 L = L>aLen?L:aLen;//记录当前和的位数 29 int k; 30 for(k = 0;k<L;k++) 31 { 32 if(BigInt[k]>=10) 33 { 34 BigInt[k] -= 10; 35 BigInt[k+1] += 1; 36 } 37 } 38 if(BigInt[k]) L++; 39 40 } 41 42 return 0; 43 }
以上是关于POJ 1503 -- Integer Inquiry的主要内容,如果未能解决你的问题,请参考以下文章