hdu1047(Java)大数相加
题目大意:输入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
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.)
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.
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.
0
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)大数相加的更多相关文章
- Java大数相加-hdu1047
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目描述: 题意有点绕,但是仔细的读了后就发现是处理大数相加的问题.注意:输入数据有多组,每组输 ...
- java大数相加
import java.math.BigInteger; import java.util.Scanner; public class Bignum{ public static void ma ...
- hdu1715(Java)大数相加
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...
- hdu 1002 java 大数相加
package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...
- Java大数相加(多个大数相加)-hdu1250
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 题目描述: 题目大意是:已知一个Hat's Fibonacci序列,该序列满足F(1) = 1, ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
- Java实现大数相加、相乘(不使用BigInteger)
大数相加: package algorithm; //使用BigInteger类验证 import java.math.BigInteger; public class BigAdd { public ...
- 用字符串模拟两个大数相加——java实现
问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...
- Java 大数相乘、大数相加、大数相减
思路来源:: https://blog.csdn.net/lichong_87/article/details/6860329 /** * @date 2018/6/22 * @description ...
随机推荐
- spring cloud官方文档提到的服务开发的12项要素。
I. Codebase 从一个代码库部署到多个环境. II. Dependencies 使用显式的声明隔离依赖,即模块单独运行,并可以显式管理依赖. III. Config 在系统外部存储配置信息. ...
- 关于方程x^2+y^2=p (p为素数)的解问题
问题描述:对于方程,其中为素数,x,y为整数,且,输出符合条件的x,y. 分析:对于本方程,我们通过费马平方和定理知道,只有奇素数p满足这个条件时才有解. 那么当此方程有解时,解有几个呢?很明显不可能 ...
- Linux 启动参数介绍
Linux 启动参数介绍 取自2.6.18 kernel Documentation/i386/boot.txt 文件中介绍 vga= 这里的不是一个整数(在C语言表示法中,应是十进制,八进制或者十六 ...
- Form – 保存自動關閉當前窗口
FAQ: 在BUTTON的触发器中,写如下代码, commit_form; go_bloack('你想显示的那个window的block'); --或者写 show_view('你要显示的canvas ...
- android & Linux uevent机制
Linux uevent机制 Uevent是内核通知android有状态变化的一种方法,比如USB线插入.拔出,电池电量变化等等.其本质是内核发送(可以通过socket)一个字符串,应用层(andro ...
- 函数page_rec_get_next_const
/************************************************************//** Gets the pointer to the next recor ...
- apache开源项目--Ignite
Apache Ignite 内存数组组织框架是一个高性能.集成和分布式的内存计算和事务平台,用于大规模的数据集处理.Ignite 为应用和不同的数据源之间提供一个高性能.分布式内存中数据组织管理的框架 ...
- linux 系统获取网络ip, mask, gateway, dns信息小程序
net_util.c #define WIRED_DEV "eth0" #define WIRELESS_DEV ...
- Android从零单排之免费短信验证
介绍 短信验证功能大家都很熟悉了.在很多地方都能见到,注册新用户或者短息验证支付等.短信验证利用短信验证码来注册会员,大大降低了非法注册,很大程度上提高了用户账户的安全性. 目前市面上已经有了很多提供 ...
- linux下安装
挂载 1.虚拟机里选择ios文件2.挂载光驱命令: cd / mount /mnt/cdrom/ cd /mnt/cdrom/ ls 卸载 cd /umount /mnt/cdrom/ 安装 XXX. ...