HDOJ_ACM 2054 使用java

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

 

这道题应该考虑到小数,大数,0050,50 等等这些情况 用C语言或者C++会比较麻烦

但是在Java中有 BigDeimal 正好解决这个问题 (ACM可以用JAVA提交)

代码如下:

import java.util.*;
import java.math.BigDecimal;

public class Main
{
        public static void main(String args[])
       {
              BigDecimal a,b;
           Scanner in=new Scanner(System.in);
           while(in.hasNextBigDecimal())
           {
                  a=in.nextBigDecimal();
                  b=in.nextBigDecimal();
                  if(a.compareTo(b)==0) System.out.println("YES");
                  else System.out.println("NO");
           }
          
       }
}

  

 

posted on 2014-11-27 19:29  卤肉饭  阅读(306)  评论(0)    收藏  举报

导航