Integer Inquiry
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 32674 |
|
Accepted: 12789 |
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
Source
East Central North America 1996
original title link: http://poj.org/problem?id=1503
PS: Large number of variants of addition, or Java good!AC Code:
Import Java.math.biginteger;import Java.util.scanner;public class Main {public static void main (string[] args) {//TODO Au to-generated method Stubscanner sc = new Scanner (system.in), while (Sc.hasnext ()) {BigInteger sum = new BigInteger ("0", 10); BigInteger x = Sc.nextbiginteger (), if (X.equals (new BigInteger ("0"))) {//note, and ' 0 ' are judged with the new object!!! SYSTEM.OUT.PRINTLN (sum); break;} sum = Sum.add (x);}}
AC code 2;
#include <stdio.h> #include <string.h>char a[1000];int sum[1000],data[1000];int length_sum;int main () {int I,j,length_a,jin,temp; memset (sum,0,sizeof (sum)); while (1) {scanf ("%s", a); Length_a=strlen (a); if (a[0]== ' 0 ' &&length_a==1) {length_sum=999; while (sum[length_sum]==0) {length_sum--; } for (i=length_sum; i>=0; i--) {printf ("%d", sum[i]); } break; } else {memset (data,0,sizeof (data)); for (j=0,i=length_a-1; i>=0; i--) {data[j++]=a[i]-' 0 '; } for (jin=0,i=0; i<1000; i++) {Temp=sum[i]+data[i]+jin; sum[i]=temp%10; JIN=TEMP/10; }}} return 0;}
POJ 1053 Integer Inquiry (large number addition, or Java Dafa good)