输入四个整数a, b, c, d,表示两个分数a/b和c/d。要求输出最简分数以及两个分数相等和大小的比较结果。
样例输入
1 7 26 25
样例输出
zrf is:1/7; ssh is:26/25
(zrf==ssh) is:0; (zrf<ssh) is:1
(zrf==ssh) is:0; (zrf<ssh) is:1
import java.util.Scanner;
public class algo_155 {
static long gcd(long m,long n){
long temp;
while(n>0){
temp = m%n;
m=n;
n=temp;
}
return m;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
long d = sc.nextLong();
a = a/gcd(a,b);
b = b/gcd(a,b);
c = c/gcd(c,d);
d = d/gcd(c,d);
int flag1=1,flag2=0;
if(a!=c)
flag1=0;
if(a*d<b*c)
flag2=1;
System.out.println("zrf is:"+a+"/"+b+"; ssh is:"+c+"/"+d);
System.out.println("(zrf==ssh) is:"+flag1+"; (zrf<ssh) is:"+flag2);
}
}