Integer InquiryTime
limit:MS
Memory Limit:10000KB
64bit IO Format:%i64d &%i64u SubmitStatus
Description
One of the first users of BIT ' s new supercomputer was Chip Diller. He extended his exploration of powers's 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 for 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 would consist of the lines of text, each of which contains a single verylonginteger. Each verylonginteger'll be is fewer characters in length, and would only contain digits (no verylonginteger would be n egative).
The final input line would contain a single zero in a line by itself.
Output
Your program should output the sum of the verylongintegers given in the input.
Sample Input
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900
Sample Output
370370367037037036703703703670
Large number addition problem:
#include <string.h> #include <stdio.h> #include <stdlib.h>char str[105],sum[105],ssum[105];int main () {char c;int len,i,flag,slen,k,j;//memset (sum, ' 0 ', sizeof (sum)), Flag=1;while (~scanf ("%s", str)) {Len=strlen (str); if (len==1&&str[0]== ' 0 ') break;if (flag) {strcpy (SUM,STR); flag=0;} else{slen=strlen (sum); for (K=0;len >=0| | Slen>=0;len--, slen--, k++) { if (len>=0&&slen>=0) ssum[k]=str[len]+sum[slen]-' 0 ' +c; if (len<0&&slen>=0) ssum[k]=sum[slen]+c; if (len>=0&&slen<0) ssum[k]=str[len]+c; c=0; Carry plus clear 0 if (ssum[k]> ' 9 ') {ssum[k]-=10; C=1; }
Java:
Import Java.io.*;import java.math.*;class Bigint {public static void main (string[] args) throws exception{ String S1 = null; BigInteger bint = null; BufferedReader bin = new BufferedReader (new InputStreamReader (system.in)); S1 = Bin.readline (); while (!s1.equals ("0")) {if (bint = = null) {bint = new BigInteger (S1); } else {bint = bint. Add (new BigInteger (S1)); } S1 = Bin.readline (); } if (S1.equals ("0")) {System.out.println (bin T.tostring ()); } }}
HDU 1047 Integer Inquiry