题目大意:输入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. S5PV210的IRAM应用

    准备分析   IRAM的大小96k,其实前两个程序都在这里运行的,程序都小于16K.要实现的是从把IRAM从的前16k从IRAM的起始地址0xD0020000拷贝到0xD0024000 处,调用mai ...

  2. APK签名原理

    网上已有多篇分析签名的类似文章,但是都有一个共同的问题,就是概念混乱,混乱的一塌糊涂. 在了解APK签名原理之前,首先澄清几个概念: 消息摘要 -Message Digest 简称摘要,请看英文翻译, ...

  3. 利用逻辑运算符?"三个数字比大小

    static void Main(string[] args)        {            int a, b, c;            while (true)            ...

  4. c#浅谈反射内存的处理

    这段时间由于公司的项目的要求,我利用c#的反射的机制做了一个客户端框架.客户端里的所有的模块都是以一定形式进行提供,例如:FORM,UserControl. 在做的过程中很简单与愉快.具体的过程如下: ...

  5. memcached SASL验证状态安全绕过漏洞

    漏洞版本: memcached 1.x 漏洞描述: Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载. Memcached在处理链接的SASL验证状态时存在错 ...

  6. Linux Kernel ‘exitcode_proc_write()’函数本地缓冲区溢出漏洞

    漏洞名称: Linux Kernel ‘exitcode_proc_write()’函数本地缓冲区溢出漏洞 CNNVD编号: CNNVD-201311-061 发布时间: 2013-11-07 更新时 ...

  7. [OpenJudge] 平方和

    平方和 总时间限制: 3000ms 内存限制: 65536kB 描述 给出n(1<=n<=500000)个数字,下标从1开始 执行m(1<=m<=500000)次操作,操作可分 ...

  8. 部署解决方案包 (SharePoint Server 2010)

    转:http://technet.microsoft.com/zh-cn/library/cc262995(v=office.14).aspx 本文介绍各个解决方案包,及其在 Microsoft Sh ...

  9. 设置oracle11g空表exp导出

    1.Oracle11g默认对空表不分配segment,故使用exp导出Oracle11g数据库时,空表不会导出. 2.设置deferred_segment_creation 参数为FALSE后,无论是 ...

  10. haporoxy的keeplaive ZZ

    转载一个别人总结的http://hi.baidu.com/%D3%E3%B5%C1%B5%C1/blog/item/04ffd1b1854f69ef30add1e8.html httpclose, h ...