A+B Problem IV
描述acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着能不能写个程序把这个问题给解决了。
- 输入
- 包含多组测试数据
每组数据包含两个正数A,B(可能为小数且位数不大于400) - 输出
- 每组输出数据占一行,输出A+B的结果,结果需要是最简的形式。
- 样例输入
-
1.9 0.1
0.1 0.9
1.23 2.1
3 4.0 - 样例输出
-
2
1
3.33
7import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
BigDecimal a;
BigDecimal b;
String s;
String words[]; while(scanner.hasNext()){
a=scanner.nextBigDecimal();
b=scanner.nextBigDecimal();
s=a.add(b).toString();
words=s.split("\\.");
System.out.print(words[0]); if(s.contains(".")){
words[1]=new StringBuffer(words[1]).reverse().toString();
words[1]=words[1].replaceAll("^(0*)","");
words[1]=new StringBuffer(words[1]).reverse().toString(); if(words[1].compareTo("")!=0)
System.out.print("."+words[1]);
}
System.out.println();
} }
}
A+B Problem IV的更多相关文章
- NYOJ--513--A+B Problem IV(大数)
A+B Problem IV 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着能不能写个程序把这 ...
- nyoj A+B Problem IV
A+B Problem IV 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着能不能写个程序把这 ...
- nyoj 513-A+B Problem IV (java BigDecimal, stripTrailingZeros, toPlainString)
513-A+B Problem IV 内存限制:64MB 时间限制:1000ms 特判: No 通过数:1 提交数:2 难度:3 题目描述: acmj最近发现在使用计算器计算高精度的大数加法时很不方便 ...
- SOJ4480 Easy Problem IV (并查集)
Time Limit: 3000 MS Memory Limit: 131072 K Description 据说 你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过六个人你就能够认识任 ...
- nyoj_513_A+B Problem IV_20130131532
A+B Problem IV 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着 ...
- ACM之Java速成(3)
ACM中Java.大数处理 先上个代码: import java.math.*; import java.util.*; class Main{ public static void main(Str ...
- 【大数处理、正则表达式】NYOJ-513
[正则] 正则表达式是一种文本模式,包括普通字符(例如,a 到 z 之间的字母)和特殊字符(称为“元字符”). 模式描述在搜索文本时要匹配的一个或多个字符串. 常用字符: //正则表达式 //$ 匹配 ...
- akoj-1048-求某一整数序列的全排列问题
求某一整数序列的全排列问题 Time Limit:1000MS Memory Limit:65536K Total Submit:35 Accepted:16 Description 现有一整数序列 ...
- LeetCode 188. Best Time to Buy and Sell Stock IV (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
随机推荐
- [C++ STL] set使用详解
一.set介绍: set容器内的元素会被自动排序,set与map不同,set中的元素即是键值又是实值,set不允许两个元素有相同的键值.不能通过set的迭代器去修改set元素,原因是修改元素会破坏se ...
- ACM_三角形的周长
三角形的周长 Time Limit: 2000/1000ms (Java/Others) Problem Description: 有n根棍子,棍子i的长度为ai,想要从中选出3根棍子组成周长尽可能长 ...
- 转:python中使用txt文本保存和读取变量
问题: 在python中需要经常有需要提前生成复杂的计算结果变量的需求减少程序计算运行时间的需求,因此这里把变量存在txt文本文件中. 解决方法: 使用两个函数解决问题,一个函数把变量保存到文本文件中 ...
- 240 Search a 2D Matrix II 搜索二维矩阵 II
编写一个高效的算法来搜索 m x n 矩阵中的一个目标值.该矩阵具有以下特性: 每行的元素从左到右升序排列. 每列的元素从上到下升序排列.例如,考虑下面的矩阵:[ [1, 4, 7 ...
- 268 Missing Number 缺失的数字
给出一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数.案例 1输入: [3,0,1]输出: 2案例 2输入: [9,6,4,2,3,5,7, ...
- [转]How can I get my webapp's base URL in ASP.NET MVC
本文转自:http://stackoverflow.com/questions/1288046/how-can-i-get-my-webapps-base-url-in-asp-net-mvc May ...
- 冒泡 [Python]
冒泡Python class BubbleSort: def __init__(self): self.initArr() def initArr(self): self.arrInfo = [60, ...
- ProcessBar 与SeekBar进度条
1.进度条关键属性 2.进度条的常用方法 progress = (ProgressBar) findViewById(R.id.horiz); (1)获取第一进度条:progress.getProgr ...
- Maven对不同的测试环境用不同的参数进行打包
通过mvn package -P ${env} 加载不同配置文件 1.pom.xml中的配置 filter-dev.properties jdbc.properties
- Windows提高_1.3文件操作
文件操作 不带句柄的文件操作 // 1. 拷贝文件,第三个参数为 FALSE 表示会覆盖 // CopyFile(L"D:\\1.txt", L"E:\\2.txt&qu ...