Add large numbers

Source: Internet
Author: User

Question 1119: Integer Inquiry time limit: 1 second memory limit: 32 MB special question: No submitted: 437 solution: 228 question description: one of the first users of BIT's new supercomputer was Chip Diller. he extended his authentication of powers of 3 to go from 0 to 333 and he was Ed 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 in a single zero on a line by itself. output: Your program shocould output the sum of the VeryLongIntegers given in the input. sample input: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900 sample output: 370370367037037036703703703670 tip: note that VeryLongInteger may have leading 0 AC code: import java. util. *; import java. math. *; public class Main11 {public static void main (String agrs []) {using cin = new using (System. in); BigInteger sum, temp; sum = BigInteger. ZERO; temp = cin. nextBigInteger (); sum = temp; while (cin. hasNext () {temp = cin. nextBigInteger (); if (temp. equals (BigInteger. ZERO) break; sum = sum. add (temp);} System. out. println (sum );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.