牛客网-第一场-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(">");
   } 
  } 
 }
}
原文地址:https://www.cnblogs.com/cznczai/p/11209274.html