题目大意:输入n组数据,每组数据中又有若干长度不大于100的整数,以0结束每组数据的输入,求每组中数据之和。每两组数据输入之间有一行空格,输出也是如此。

Integer Inquiry

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17770 Accepted Submission(s):
4628

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

 
Output
Your 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 is an integer N, then a
blank line followed by N input blocks. Each input block is 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
1
123456789012345678901234567890
 
123456789012345678901234567890
 
123456789012345678901234567890
0
 
Sample Output
370370367037037036703703703670
--------------------------------------------------

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class Main1047 {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
int n=cin.nextInt();
Object obj=BigInteger.ZERO;
for(int i=0;i<n;i++){
BigInteger sum=BigInteger.ZERO;
while(true){
BigInteger b=cin.nextBigInteger();
if(b.equals(obj)){//这里也可以用commparTo(BigInteger.ZERO)==0进行判断;
System.out.println(sum);
if(i!=n-1)
System.out.println();
break;
}
sum=sum.add(b);
}
}
}
}
}

 

hdu1047(Java)大数相加的更多相关文章

  1. Java大数相加-hdu1047

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目描述: 题意有点绕,但是仔细的读了后就发现是处理大数相加的问题.注意:输入数据有多组,每组输 ...

  2. java大数相加

    import java.math.BigInteger; import java.util.Scanner; public class Bignum{    public static void ma ...

  3. hdu1715(Java)大数相加

    大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...

  4. hdu 1002 java 大数相加

    package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...

  5. Java大数相加(多个大数相加)-hdu1250

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 题目描述: 题目大意是:已知一个Hat's Fibonacci序列,该序列满足F(1) = 1, ...

  6. POJ 1503 Integer Inquiry(大数相加,java)

    题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...

  7. Java实现大数相加、相乘(不使用BigInteger)

    大数相加: package algorithm; //使用BigInteger类验证 import java.math.BigInteger; public class BigAdd { public ...

  8. 用字符串模拟两个大数相加——java实现

    问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...

  9. Java 大数相乘、大数相加、大数相减

    思路来源:: https://blog.csdn.net/lichong_87/article/details/6860329 /** * @date 2018/6/22 * @description ...

随机推荐

  1. Python标准库之urllib,urllib2

    urllib模块提供了一些高级接口,用于编写需要与HTTP服务器交互的客户端.典型的应用程序包括从网页抓取数据.自动化.代理.网页爬虫等. 在Python 2中,urllib功能分散在几个不同的库模块 ...

  2. Android 内核初识(4)属性服务器

    简介 Windows平台上有一个叫注册表的东西.注册表可以存储一些类似key/value的键值对.一般而言,系统或某些应用程序会把自己的一些属性存储在注册表中,即使下次系统重启或应用程序重启,它还能够 ...

  3. Pizza pieces

    Pizza pieces Description In her trip to Italy, Elizabeth Gilbert made it her duty to eat perfect piz ...

  4. MySQL for Excel用法

    MySQL有一款工具“MySQL for Excel”它可以提供将Excel的数据导入MySQL,或者将MySQL的数据导出到Excel的功能.简而言之,使用MySQL for Excel可以通过Ex ...

  5. 如何从Win7中提取制作Windows PE3.0

    在D盘新建文件夹winpe,在winpe中新建sources.pe3和new文件夹,把附件中提供的工具imagex连文件夹一起放到winpe目录中. 制作方法: 1.把windows7光盘(或光盘镜像 ...

  6. [TOP]疯狂的投资

    [TOP]疯狂的投资 这是罗辑思维一期<疯狂的投资>的节目笔记,这期主要是通过菲尔德铺设横跨大西洋的电缆的故事讲了创业者需要的特质和<二十一世纪资本论>的一个观念:随着自由市场 ...

  7. md5可能会被破解咋办?

    所谓加Salt,就是加点“佐料”.其基本想法是这样的——当用户首次提供密码时(通常是注册时),由系统自动往这个密码里撒一些“佐料”,然后再散列.而当用户登录时,系统为用户提供的代码撒上同样的“佐料”, ...

  8. 【Java基础】继承中的代码块和构造方法的执行顺序探索

    本文讲述有关一个类的静态代码块,构造代码块,构造方法的执行流程问题.首先来看一个例子 /** * Created by lili on 15/10/19. */ class Person{ stati ...

  9. c语言之sizeof总结

    一.sizeof的概念 Sizeof是C语言的一种单目操作符,如C语言的其他操作符++.--等.它并不是函数.Sizeof操作符以字节形式给出了其操作数的存储大小.操作数可以是一个表达式或括在括号内的 ...

  10. HW3.12

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...