链接: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"); } } } }
转载于:https://www.cnblogs.com/Weixu-Liu/p/9647596.html
相关资源:数据结构—成绩单生成器