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.

Sample Input

123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0

Sample Output

370370367037037036703703703670
第一道java题,好开森;
import java.util.*; import java.math.*; import java.io.*;
public class Main{        //外面的Main必须大写! public static void main(String[] args){ //String S大写 Scanner cin= new Scanner(System.in);
BigDecimal a=BigDecimal.valueOf(0); //组合的函数名一般后个一定得大写: BigInter BigDecimal valueOf(这前不大写) hasNext nextLine;
BigDecimal b=BigDecimal.valueOf(0); //赋初值
String str;
while(cin.hasNext())     //相当于!=EOF
{
str=cin.nextLine(); //下一行输入nextLine
if(str.equals("0")) //equals
{
break;
}
else
{
a=new BigDecimal(str); //强制转化,把str转化成大数
b=b.add(a);     //b+a; } }
System.out.println(b.toPlainString()); //println,是LN
                        //toPlainString 以字符形式输出
} }

  

poj-1503-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. hdu1047(Java)大数相加

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

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

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

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

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

  8. POJ 1503 Integer Inquiry(大数相加)

    一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...

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

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

  10. Poj 2602 Superlong sums(大数相加)

    一.Description The creators of a new programming language D++ have found out that whatever limit for ...

随机推荐

  1. 好用的Markdown编辑器汇总

    Markdown 是一种简单的.轻量级的标记语法.用户可以使用诸如 * # 等简单的标记符号以最小的输入代价生成极富表现力的文档. Markdown具有很多优点: 写作中添加简单符号即完成排版,所见即 ...

  2. hi3531的pcie atu资源重映射

    1. 设置ATU 区域号寄存器为需要配置的地址转换区编号. 2. 设置ATU Region Lower Base Address Register 和ATU Region Upper Base Add ...

  3. org.hibernate.engine.jndi.JndiException:Error parsing JNDI name[foo]

    1.错误描述 WARN:HHH00027:Could not bind factory to JNDI org.hibernate.engine.jndi.JndiException:Error pa ...

  4. nested exception is java.sql.SQLException: IO 错误

    1.错误描述 (mx.messaging.messages::ErrorMessage)#0 body = (null) clientId = "18CE3B03-9709-9DA8-763 ...

  5. Axure使用心得分享

    因为之前很少涉及到原型设计,所以对这个原型设计工具也不太熟悉,第一次使用走了不少的弯路,在这里把自己在使用过程中的心得跟大家分享一下,希望能够对大家有所帮助. 一. 元素的选择 我觉得这是Axure原 ...

  6. 芝麻HTTP: Python爬虫利器之Requests库的用法

    前言 之前我们用了 urllib 库,这个作为入门的工具还是不错的,对了解一些爬虫的基本理念,掌握爬虫爬取的流程有所帮助.入门之后,我们就需要学习一些更加高级的内容和工具来方便我们的爬取.那么这一节来 ...

  7. python实现简单排序算法

    算法 递归两个特点: 调用自身 有穷调用 计算规模越来越小,直至最后结束 用装饰器修饰一个递归函数时会出现问题,这个问题产生的原因是递归的函数也不停的使用装饰器.解决方法是,只让装饰器调用一次即可,那 ...

  8. toggle的用法(点击更换不同的function)当指定元素被点击时,在两个或多个函数之间轮流切换。

    一,用法 <html> <head> <script type="text/javascript" src="/jquery/jquery. ...

  9. thinkphp5源码解析(2)控制器

    入口文件index.php: // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 require __DIR ...

  10. ls -l 显示年份

    默认情况下ls -l命令只显示月和日,不显示年份: $ ls -llrwxrwxrwx 1 root root 7 Feb 27 16:12 bin -> usr/bin 如要要显示年份,就要使 ...