zoukankan      html  css  js  c++  java
  • hdu 2054 A == B ? (java)

    问题:
    考虑问题不周到。没有考虑到可能是小数并且存在 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");
    		}
    	}
    }


  • 相关阅读:
    GotoAndPlay 图论
    P1965 转圈游戏  快速幂
    双栈排序 图论
    威尔逊定理 数学
    n!mod p 的求法 数学
    P3195 [HNOI2008]玩具装箱TOY DP+优化
    loj6485. LJJ 学二项式定理
    loj6539. 奇妙数论题
    loj535. 「LibreOJ Round #6」花火
    loj534. 「LibreOJ Round #6」花团
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5207429.html
Copyright © 2011-2022 走看看