nyoj 524-A-B Problem (java stripTrailingZeros, toPlainString)
524-A-B Problem
内存限制:64MB
时间限制:1000ms
特判: No
通过数:2
提交数:4
难度:3
题目描述:
A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下A-B吧。
现在有两个实数A和B,聪明的你,能不能判断出A-B的值是否等于0呢?
输入描述:
有多组测试数据。每组数据包括两行,分别代表A和B。
它们的位数小于100,且每个数字前中可能包含+,- 号。
每个数字前面和后面都可能有多余的0。
每组测试数据后有一空行。
输出描述:
对于每组数据,输出一行。
如果A-B=0,输出YES,否则输出NO。
样例输入:
1
1 1.0
2.0
样例输出:
YES
NO
Java (无法提交):
import java.math.BigDecimal;
import java.util.Scanner; public class Main { public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while (scan.hasNext()){
BigDecimal Deci1 = scan.nextBigDecimal();
BigDecimal Deci2 = scan.nextBigDecimal();
String str1 = Deci1.stripTrailingZeros().toPlainString();
String str2 = Deci1.stripTrailingZeros().toPlainString();
String notUse = scan.nextLine();
if (str1.startsWith("+"))
str1 = str1.substring(1);
if (str2.startsWith("+"))
str2.substring(1);
if (str1.equals(str2))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
nyoj 524-A-B Problem (java stripTrailingZeros, toPlainString)的更多相关文章
- nyoj 513-A+B Problem IV (java BigDecimal, stripTrailingZeros, toPlainString)
513-A+B Problem IV 内存限制:64MB 时间限制:1000ms 特判: No 通过数:1 提交数:2 难度:3 题目描述: acmj最近发现在使用计算器计算高精度的大数加法时很不方便 ...
- poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)
求高精度幂 Time Limit: 500MS Memory Limit: 10000K Total Submissions: 180325 Accepted: 43460 Descripti ...
- UVA - 524 Prime Ring Problem(dfs回溯法)
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- 【志银】NYOJ《题目524》A-B Problem
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=860 My思路: 先用两个字符串储存这两个实数,然后再用另外两个字符串储存去掉符号和前后多 ...
- nyoj 473 A^B Problem
A^B Problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Give you two numbers a and b,how to know the a^ ...
- nyoj 623 A*B Problem II(矩阵)
A*B Problem II 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...
- nyoj 289 苹果 动态规划 (java)
分析:0-1背包问题 第一次写了一大串, 时间:576 内存:4152 看了牛的代码后,恍然大悟:看来我现在还正处于鸟的阶段! 第一次代码: #include<stdio.h> #inc ...
- nyoj 252 01串 动态规划( java)
当n=2时, 输出 3:当n=3时, 输出 5:当n=4时, 输出 8: #### 分析: 当n=4时,如 0101 符合条件, 当第一个位置是0时,还剩3个位置 ,与n=3时个数相等: 符合条件的为 ...
- nyoj 4 ASCII码排序 java
java输入字符:1.String s=sc.next(); 2.char a=s.charAt(0); 注意:package java 中提交不能带package java代码: import ...
随机推荐
- idea+springboot+mybatis逆向工程
前提:使用idea开发,基于springboot.用到了mybatis的逆向工程 因为之前用eclipse开发ssm比较多,现在转idea 使用springboot 踩了一些坑,在这记录一下~ 注意事 ...
- js转换页面为图片并下载
<div style="background:red;width: 600px;height: 600px;" class="test"> < ...
- docker3-镜像的使用
基本使用命令: [root@ipha-dev71- docker]# docker search python # 搜索镜像 [root@ipha-dev71- docker]# docker pul ...
- vue系列文章 --- 源码目录结构整理(三)
vue的版本是:^2.6.10 结构如下: |----- vue | |--- dist # 打包之后的目录vue文件 | | |--- vue.common.dev.js | | |--- vue. ...
- Spring Cloud - Eureka /actuator/info 如何显示信息
在pom.xml中添加 <!-- actuator监控信息完善 --> <dependency> <groupId>org.springframework.boot ...
- Python 用科学的方法判断函数/方法
from types import MethodType,FunctionType def check(arg): """ 检查arg是方法还是函数? :param ar ...
- yii2中commands的简单应用
class HelloController extends Controller { /** * This command echoes what you have entered as the me ...
- 关于php注释那些事
代码注释的作用 --- 为自己,也为别人. 永远不要过于相信自己的理解力!当你思路通畅,思如泉涌,进入编程境界,你可以很流畅的实现某个功能,但这种一泻千里的流畅可能只停留在了当时的状态.当你几个月, ...
- 学习笔记01HTML
1.五大浏览器:IE,FireFox,Chrome,Opera,Safari(Apple)所有浏览器都是这五大浏览器中作为核心引擎的.Trident(引擎):就是IE浏览器的WebBrowser控制. ...
- 学习笔记66_DBSCAN聚类算法