A == B ?

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2054

Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
 
Input
each test case contains two numbers A and B.
 
Output
for each case, if A is equal to B, you should print "YES", or print "NO".
 
Sample Input
1 2
2 2
3 3
4 3
 
Sample Output
NO
YES
YES
NO
 

注意:

1)在用JAVA的BigDecimal时,用直接用equal()会WA的,因为equal()表示此 BigDecimal 与指定的 Object 的相等性。(2.0 与2.000是不相等的),所以应该用stripTrailingZeros()来去掉后面的0。

2)注意“number”可能包括小数。

3)此方法也可以用compareTo()

JAVA代码1:

import java.math.BigDecimal;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner inScanner = new Scanner(System.in);
BigDecimal bigDecimal;
BigDecimal bigDecimal2;
while(inScanner.hasNext()) {
bigDecimal = inScanner.nextBigDecimal();
bigDecimal2 = inScanner.nextBigDecimal();
if(bigDecimal.stripTrailingZeros().equals(bigDecimal2.stripTrailingZeros())) {
System.out.println("YES");
} //stripTrailingZeros() 要使用。
else {
System.out.println("NO");
}
}
}

JAVA代码2:

import java.math.BigDecimal;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner inScanner = new Scanner(System.in);
BigDecimal bigDecimal;
BigDecimal bigDecimal2;
while(inScanner.hasNext()) {
bigDecimal = inScanner.nextBigDecimal();
bigDecimal2 = inScanner.nextBigDecimal();
if(bigDecimal.compareTo(bigDecimal2)==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
} }

(stripTrailingZeros)A == B hdu2054的更多相关文章

  1. (stripTrailingZeros)A == B hdu2054

    A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  2. nyoj 524-A-B Problem (java stripTrailingZeros, toPlainString)

    524-A-B Problem 内存限制:64MB 时间限制:1000ms 特判: No 通过数:2 提交数:4 难度:3 题目描述: A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下 ...

  3. nyoj 513-A+B Problem IV (java BigDecimal, stripTrailingZeros, toPlainString)

    513-A+B Problem IV 内存限制:64MB 时间限制:1000ms 特判: No 通过数:1 提交数:2 难度:3 题目描述: acmj最近发现在使用计算器计算高精度的大数加法时很不方便 ...

  4. poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)

    求高精度幂 Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 180325   Accepted: 43460 Descripti ...

  5. HDU-2054 A==B?

    #include<stdio.h>#include<string.h>char n[100000], m[100000];int main(){ int i, j, len_n ...

  6. hdu2054 通过率低是有理由的

    这虽然是一道水题,但却巨坑,他题面上不说数据范围,也没有说数据类型,事实就是数据范围巨大,整型实型都有,所以必须用字符串去写,但是又涉及到小数,所以还要删除小数后面多余的0,比如1==1.0000,这 ...

  7. HDU-2054.A==B?(字符串简单处理)

    这道题......被我各种姿势搞死的... 本题大意:给出两个数A和B,判断A和B是否相等,对应输出YES or NO. 本题思路:本题我有两种思路,第一种是直接去除前导零和后导零然后稍加处理比较字符 ...

  8. HDU2054:A == B ?

    A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. A == B ?(hdu2054)

    输入格式:直接循环,同时输入两个不带空格未知长度的字符串. 思考:不带空格未知长度且同时输入,用两个char s[maxsize]定义两个字符数组,再用scanf_s()函数同时输入两个字符串. 注意 ...

随机推荐

  1. 词频统计 List Array

    c# 使用数组进行词频统计 1.先考虑要是使用的数据结构: Array在在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单,但是数组存在一些不足的地方.在数组的两个数据间插入数据 ...

  2. 个人博客week2

    1. 是否需要有代码规范 对于是否需要有代码规范,请考虑下列论点并反驳/支持: 这些规范都是官僚制度下产生的浪费大家的编程时间.影响人们开发效率, 浪费时间的东西. 我是个艺术家,手艺人,我有自己的规 ...

  3. [BUAA软工]第一次博客作业---阅读《构建之法》

    [BUAA软工]第一次博客作业 项目 内容 这个作业属于哪个课程 北航软工 这个作业的要求在哪里 第1次个人作业 我在这个课程的目标是 学习如何以团队的形式开发软件,提升个人软件开发能力 这个作业在哪 ...

  4. "留拍"-注册/登录详解

    1. 注册 打开 “留拍” 软件,进入 主页面 ,然后按 注册 按钮: 在注册页面什么内容 都没有写 上去的情况下,按 完成 按钮: 首先把URL封装起来: public class URL { pu ...

  5. shell脚本--显示文本内容

    shell脚本显示文本内容及相关的常用命令有cat.more.less.head.tail.nl 首先是cat,cat最常用的就是一次性显示文件的所有内容,如果一个文件的内容很多的话,那么就不是很方便 ...

  6. PAT L2-012 关于堆的判断

    https://pintia.cn/problem-sets/994805046380707840/problems/994805064676261888 将一系列给定数字顺序插入一个初始为空的小顶堆 ...

  7. HDU 2071 Max Num

    http://acm.hdu.edu.cn/showproblem.php?pid=2071 Problem Description There are some students in a clas ...

  8. add (db.collection.add)添加数据

    db.collection('cheshi').add({ data: { cheshi:4, } }).then((res) => { console.log(res) })

  9. python之tkinter使用-多选框实现开关操作

    # tkinter的Checkbutton实现开关操作 import tkinter as tk root = tk.Tk() root.title('开关') root.geometry('170x ...

  10. Lodop窗口的按钮、权限,隐藏或设置功能不可用

    Lodop隐藏某个按钮或部分,具体参考Lodop技术手册 SET_SHOW_MODE篇.以下是几个例子,(对应下图图片): 第一种:LODOP.SET_SHOW_MODE ("HIDE_PB ...