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 ...
 
随机推荐
- Oracle虚拟机配置
			
1.正常安装 .配置 3.监听配置 4.重启监听服务 5.防火墙端口放行 6.Oracle客户端连接工具测试
 - $CF241D\ Numbers$
			
problem 题目大意: 给你n个数和p,都小于50000要求留下若干个数字,使得剩下的数字异或为0,并且从左到右串联起来可以被p整除,求一种这样的方案. 搜索 #include <bits/ ...
 - 数据结构之顺序队列(C实现)
			
一.队列是什么 队列是一种可以实现“先进先出”的存储结构. 队列通常可以分为两种类型: 一.顺序队列,采用顺序存储,当长度确定时使用. 顺序队列又有两种情况: ①使用数组存储队列的称为静态顺序队列. ...
 - U - Relatives(欧拉函数)
			
Description Given n, a positive integer, how many positive integers less than n are relatively prime ...
 - C - GCD LCM
			
Description The GCD of two positive integers is the largest integer that divides both the integers w ...
 - TensorFlow---image recognition--classify_image运行、文件说明与错误(路径)解决
			
tutorial系列mnist已经玩过了,这篇玩一下 classify_image,其实就是image label.模型已经训练好的了,直接下载下来在.pb文件中. 本机环境: Win10 + Pyt ...
 - [转]mysql update操作
			
转自:http://www.cnblogs.com/ggjucheng/archive/2012/11/06/2756392.html update语法 Single-table语法: UPDATE ...
 - 编写UI自动化测试用例原则
			
1.一个脚本是一个完整的场景,从用户登陆操作到用户退出系统关闭浏览器.2.一个脚本脚本只验证一个功能点,不要试图用户登陆系统后把所有的功能都进行验证再退出系统3.尽量只做功能中正向逻辑的验证,不要考虑 ...
 - Ubuntu 16.04安装Kate文本编辑工具
			
Kate支持很多语言,比如NASM,比SBL3低那么一点,但是比Gedit好. 安装: sudo apt-get install kate 启动: 额外配置: 1.安装Kwrite sudo apt- ...
 - POJ_1163_The triangle
			
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 40079 Accepted: 24144 De ...