问题:
考虑问题不周到,没有考虑到可能是小数而且存在 1.0=1;01=1的情况。
本题使用了BigDecimal类,此类适用于高精度的数此时解决了小数和01=1的问题,
该类比较方式中n.equal(m)比较精度,而n.compareTo(m)==0只比较数值适用于该题。
A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 73236 Accepted Submission(s): 11545
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
代码:
import java.math.BigDecimal; import java.util.*; public class Main{ public static void main(String[] args) { Scanner cin=new Scanner(System.in); while(cin.hasNextBigDecimal()){ BigDecimal n=cin.nextBigDecimal(); BigDecimal m=cin.nextBigDecimal(); if(n.compareTo(m)==0) System.out.println("YES"); else System.out.println("NO"); } } }
时间: 2024-11-02 15:47:29