HDOJ 1047 Integer Inquiry


JAVA睑板....

Integer Inquiry

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


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

Source
East Central North America 1996


import java.util.*;
import java.math.*;public class Main
{public static void main(String[] args){Scanner cin= new Scanner(System.in);int n=cin.nextInt();boolean flag=false;while(n-->0){if(flag==false) flag=true;else System.out.println("");BigInteger ans=BigInteger.ZERO;while(cin.hasNextBigInteger()){BigInteger m=cin.nextBigInteger();if(m.equals(BigInteger.ZERO))break;ans=ans.add(m);}System.out.println(ans);}}
}



版权声明:本文博客原创文章,博客,未经同意,不得转载。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544524.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

高并发下秒杀商品,必须知道的9个细节

高并发下如何设计秒杀系统?这是一个高频面试题。这个问题看似简单,但是里面的水很深,它考查的是高并发场景下,从前端到后端多方面的知识。秒杀一般出现在商城的促销活动中,指定了一定数量(比如:…

weakhashmap_Java WeakHashMap keySet()方法与示例

weakhashmapWeakHashMap类的keySet()方法 (WeakHashMap Class keySet() method) keySet() method is available in java.util package. keySet()方法在java.util包中可用。 keySet() method is used to retrieve all the key exists in this map to be viewed in a set. keySet…

最小拍控制系统详细解读(阶跃输入+速度输入2个案例)【Simulink仿真】

目录索引1.符号说明与结构框图2.最小拍控制系统构造原则2.1数字控制器D(z)的构造3.简单控制对象的最小拍控制器设计3.1阶跃输入3.2速度输入1.符号说明与结构框图 y(k)——系统响应输出的离散值u(k)——数字PID控制输出的离散值r(k)——期望输出的离散值(事先已知&a…

php中重写和final关键字的使用

为什么把重写和final放在一起,原因就是一条:final的意思是不可更改的,也就是说final定义的东西是不可改变的,下面具体来说一下。 来看一段简单的代码: 1 class BaseClass {2 final public function test() {3 …

java vector_Java Vector lastElement()方法与示例

java vector向量类的lastElement()方法 (Vector Class lastElement() method) lastElement() method is available in java.util package. lastElement()方法在java.util包中可用。 lastElement() method is used to return the last element of this Vector. lastElement()方法…

SpringBoot官方热部署和远程调试神器,真带劲!

平时使用SpringBoot开发应用时,修改代码后需要重新启动才能生效。如果你的应用足够大的话,启动可能需要好几分钟。有没有什么办法可以加速启动过程,让我们开发应用代码更高效呢?今天给大家推荐一款SpringBoot官方的热部署工具spri…

【Python】输入任意个数元素并保存至列表

目录1.导入任意个数元素到列表1.1.编程思路1.2.代码片2.查找一个重复元素在列表中的所有位置2.1.编程思路2.2代码片1.导入任意个数元素到列表 1.1.编程思路 输入未知个数的元素需要用列表来存储,由于Python具有内存的动态分配能力,列表不需要手动动态分…

MySQL 性能优化的 9 种姿势,面试再也不怕了!

大家好,我是磊哥!今天给大家分享一些简单好用的数据库优化方式!1、选择最合适的字段属性Mysql是一种关系型数据库,可以很好地支持大数据量的存储,但是一般来说,数据库中的表越小,在它上面执行的…

containsall_Java Vector containsAll()方法与示例

containsall向量类containsAll()方法 (Vector Class containsAll() method) containsAll() method is available in java.util package. containsAll()方法在java.util包中可用。 containsAll() method is used to test the existence of all the elements of this Vector in t…

Excel的规划求解【详细步骤】

本文目录1.说明2.准备加载项步骤1步骤2步骤33.线性规划问题步骤4步骤5步骤61.说明 使用Lingo程序也可以实现线性规划、非线性规划以及0-1规划,但是在缺少Lingo程序的情况下,我们使用Excel照样可以很容易地完成。在这里我给大家提供了解决此类问题的详细…

4 种方法!检查字符串是否为合法的日期格式

哈喽大家好,今天咱们来讲一下,Java 中如何检查一个字符串是否是合法的日期格式?为什么要检查时间格式?后端接口在接收数据的时候,都需要进行检查。检查全部通过后,才能够执行业务逻辑。对于时间格式&#x…

linux下tomcat无法显示图片验证码

在catalina.sh中的-Djava.io.tmpdir"$CATALINA_TMPDIR" \后一行增加 -Djava.awt.headlesstrue \ 共8处转载于:https://blog.51cto.com/zhangfeikr/1673312

Java Throwable toString()方法与示例

Throwable类toString()方法 (Throwable Class toString() method) toString() Method is available in java.lang package. toString()方法在java.lang包中可用。 toString() Method is used to return a short description of the exception. toString()方法用于返回对该异常的…

【Matlab】根据图生成带权邻接矩阵,并求出最短路径

目录图的简介无向图(Graph)生成带权邻接矩阵求两点最短路径有向图(Digraph)生成带权邻接矩阵求最短路径图的简介 图是拓扑学中的一个重要概念,分为无向图和有向图两种。图有两个重要属性,即点(…

阿里二面:为什么要分库分表?

在高并发系统当中,分库分表是必不可少的技术手段之一,同时也是BAT等大厂面试时,经常考的热门考题。你知道我们为什么要做分库分表吗?这个问题要从两条线说起:垂直方向 和 水平方向。1 垂直方向垂直方向主要针对的是业务…

java scanner_Java Scanner nextDouble()方法与示例

java scanner扫描仪类的nextDouble()方法 (Scanner Class nextDouble() method) nextDouble() method is available in java.util package. nextDouble()方法在java.util包中可用。 nextDouble() method is used to scans the next token of the input scanned into a double v…

Java 中 List 分片的 5 种方法!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)前些天在实现 MyBatis 批量插入时遇到了一个问题,当批量插入的数据量比较大时,会导致程序执行报错&a…

Matlab仿真炮弹飞行轨迹——探究射弹参数对飞行轨迹的影响

目录1.分析炮弹受力2.设定参数并仿真3.通过仿真寻找最佳射弹速度3.1.射弹角度的影响3.2.射弹速率的影响3.3.炮弹属性和空气的影响3.3.1.空气阻力系数的影响3.3.2.炮弹质量的影响1.分析炮弹受力 假设炮弹在飞行过程中可以看成质点,运动时仅考虑初始速度、重力加速度…

EL与JSTL注意事项汇总

EL使用表达式(5一个 问题) JSTL使用标签(5问题) 什么是EL。它可以用做? EL全名Expression Language在JSP使用页面 格公式${表达式} 样例${requestScope.customer.id} 功能: 1.才四个域对象中取出属性数据显…

nextboolean()_Java Random nextBoolean()方法与示例

nextboolean()随机类nextBoolean()方法 (Random Class nextBoolean() method) nextBoolean() method is available in java.util package. nextBoolean()方法在java.util包中可用。 nextBoolean() method is used to return the next pseudo-random Boolean value from this Ra…