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. Vxworks 6.6系列下载地址

    Vxworks 6.6系列下载地址: ---------------------------------- ftp://ftp.windriver.speedera.net/ftp.windriver ...

  2. ATCA构架

    ATCA(Advanced Telecom Computing Architecture)标准即先进的电信计算平台,它脱胎于在电信.航天.工业控制.医疗器械.智能交通.军事装备等领域应用广泛的新一代主 ...

  3. Java中的List转换成JSON报错(五)

    1.错误描述 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanu ...

  4. bit 和 byte

    bit bit是计算机的最小的存储单元,一切数据最终都以bit的形式存放在计算机之中. 一个bit有且只有两种状态.要么是0,要么是1.像这样: 多个bit组合在一起就可以构成更复杂的数据.例如,8个 ...

  5. Duplicate entry '0' for key 'PRIMARY'的一种可能的解决办法

    在MySQL设计好数据库往往数据库中插入数据的时候, 因为主键ID默认是不赋值的,只给其他项目赋值了,相关的SQL代码是这样的 StringBuilder strSql = new StringBui ...

  6. 前端测试框架对比(js单元测试框架对比)

    前端测试框架对比(js单元测试框架对比) 本文主要目的在于横评业界主流的几款前端框架,顺带说下相关的一些内容. 测试分类 通常应用会有 单元测试(Unit tests) 和 功能测试(Function ...

  7. LinearRegression 线性回归

    一.预测 先来看看这样一个场景: 假如你手头有一套房子要出售,你咨询了房产中介.中介跟你要了一系列的数据,例如房子面积.位置.楼层.年限等,然后进行一系列计算后,给出了建议的定价. 房产中介是如何帮你 ...

  8. 你需要了解的高可用方案之使用keepalived搭建双机热备一览

    在之前一篇使用nginx搭建高可用的解决方案的时候,很多同学会问,如果nginx挂掉怎么办,比如下面这张图: 你可以清楚的看到,如果192.168.2.100这台机器挂掉了,那么整个集群就下线了,这个 ...

  9. 【CJOJ2499】【DP合集】棋盘 chess

    Description 给出一张 n × n 的棋盘,格子有黑有白.现在要在棋盘上放棋子,要求: • 黑格子上不能有棋子 • 每行每列至多只有一枚棋子 你的任务是求出有多少种合法的摆放方案.答案模 1 ...

  10. MySQL配置文件

    [mysqld]datadir=/usr/local//mysql/data    #数据存放位置socket=/var/lib/mysql/mysql.sockuser=mysqllower_cas ...