Hangzhou Electric 1047 (Integer Inquiry) Java water over

Source: Internet
Author: User

Click to open Hangzhou electric 1047

Problem Descriptionone 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.)


Inputthe input would consist of in most of the lines of text, each of the 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.


Outputyour 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 was an integer N and then a blank line followed by N input blocks. Each input block was 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
31234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900 0


Sample Output
370370367037037036703703703670 370370367037037036703703703670 0

Note: Formatting problems!!

Code implementation
Import Java.math.biginteger;import java.util.scanner;class main{public    static void Main (string[] args) {        Scanner sc = new Scanner (system.in);        int n = sc.nextint ();        while (n-->0) {   BigInteger Sum=biginteger.zero;            BigInteger x;        while (Sc.hasnextbiginteger ()) {            x=sc.nextbiginteger ();            if (x.equals (biginteger.valueof (0))) {            System.out.println (sum);            break;            } else{            Sum=sum.add (x);            }            }            if (n!=0) {            System.out.println ();}}}}    


Hangzhou Electric 1047 (Integer Inquiry) Java water over

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.