牛客网-第一场-J-Fraction Comparision

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            BigInteger x = in.nextBigInteger();
            BigInteger a = in.nextBigInteger();
            BigInteger y = in.nextBigInteger();
            BigInteger b = in.nextBigInteger();
            int re = x.multiply(b).compareTo(y.multiply(a));
            if(re==-1)
                System.out.println("<");
            else if(re==1)
                System.out.println(">");
            else 
                System.out.println("=");
        }
    }
}

数学计算

import java.util.Scanner;

public class Main{
 public static void main(String[] args) {

  Scanner in = new Scanner(System.in);

  while(in.hasNext()) {

   long x = in.nextLong();
   long a = in.nextLong();
   long y = in.nextLong();
   long b = in.nextLong();

   long x1 = x/a;
   long x2 = x%a;  //利用求余跟整数 得到答案
   long y1 = y/b;
   long y2 = y%b;

   long r1 = x2 * b;
   long r2 = y2 * a;

   if(x1 == y1 && r1 == r2)
    System.out.println("=");
   else if(x1 < y1 ||(x1 == y1 && r1 < r2)){
    System.out.println("<");
   }
   else {
    System.out.println(">");
   } 
  } 
 }
}
全部评论

相关推荐

10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务