题目大意:输入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. lib 合并

    方法1: 命令如下:lib.exe lib1.lib lib2.lib ... /out:hw.lib 另一种合并的方法: 思路:lib.exe 可以把lib文件里的obj文件取出来,然后把这些obj ...

  2. tlplayer for ios V1.1.1加密测试版本

    2014-06-22 修正稳定性. 大家还是可以从原来的下载地址下载. 此为tlplayer for ios版本,可以播放加密视频与非加密视频. 加密视频下载地址:http://blog.csdn.n ...

  3. 在SQL2005实现维护计划-备份数据库

    一.備份數據庫維護計劃方案 [注]: 1.先啟動SQL Server Agent服務 2..交易記錄備份 (只限於完整和大量記錄復原模式). 3.下面中”清除備份trn文件” & “清除備份日 ...

  4. Android的string-array数据源简单使用

    在Android中,用string-array是一种简单的提取XML资源文件数据的方法. 例子如下: 把相应的数据放到values文件夹的arrays.xml文件里 <?xml version= ...

  5. Vlan技术总结

    VLAN主要有两个作用: vlan可以有效的控制广播域的范围 vlan可以分组设备,增强局域网的安全性(业务隔离) vlan的范围: 一共有4096个vlan,vlan 1为默认vlan.但其中vla ...

  6. 远程连接centos

    yum install tigervnc   yum install tigervnc-server Windows 7下载客户端 tigervnc-1.2.0.exe,在http://sourcef ...

  7. Java笔记(八)……数组

    数组的概念 同一种类型数据的集合.其实数组就是一个容器. 数组的好处 可以自动给数组中的元素从0开始编号,方便操作这些元素. 数组的格式 元素类型[] 数组名 = new 元素类型[个数]; int[ ...

  8. 五指cms标签说明汇总

    1.栏目列表标签 只有一级导航: {wz:content action="category" cid="0" pagesize="100" ...

  9. CSS書寫規範及CSS Hack

    基本原则: CSS样式可细分为3类:自定义样式.重新定义HTML样式.链接状态样式. 样式为设计师自定义的新 CSS 样式,影响被使用本样式的区域,用于完成网页中局部的样式设定. 样式名 “.”+“相 ...

  10. 解决 this virtual machine’s policies are too old to be run by this version of vmware workstation”

    VMWare从6.0升级到9.0,打开以前的虚拟机报错如下:“this virtual machine’s policies are too old to be run by this version ...