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

NOjava

YESblog

YESip

NOci

 

這道題應該考慮到小數,大數,0050,50 等等這些狀況 用C語言或者C++會比較麻煩it

可是在Java中有 BigDeimal 正好解決這個問題 (ACM能夠用JAVA提交)io

代碼以下:class

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");
           }
          
       }
}
相關文章
相關標籤/搜索