链接:https://ac.nowcoder.com/acm/contest/881/J
来源:牛客网
Bobo has two fractions xaxa and ybyb. He wants to compare them. Find the result.
输入描述:
The input consists of several test cases and is terminated by end-of-file. Each test case contains four integers x, a, y, b. * 0≤x,y≤10180≤x,y≤1018 * 1≤a,b≤1091≤a,b≤109 * There are at most 105105 test cases.
输出描述:
For each test case, print `=` if xa=ybxa=yb. Print `<` if xa<ybxa<yb. Print `>` otherwise.
示例1
输入
复制
1 2 1 1 1 1 1 2 1 1 1 1
输出
复制
< > =
#include<bits/stdc++.h>
using namespace std;
void Output(long long a, long long b)
{
if(a<b) {
cout<<"<"<<endl;
}
else if(a==b) {
cout<<"="<<endl;
}
else {
cout<<">"<<endl;;
}
}
/*
分数比较:x/a 和 y/b
换成 x*b 和 y*a
先约分,假分数 化成 整数+真分数
*/
int main()
{
long long x, a, y, b, m, n;
while(scanf("%lld%lld%lld%lld", &x, &a, &y, &b)!=EOF) {
m = x/a;
n = y/b;
if(m!=n) {//整数部分
Output(m, n);
}
else {//小数部分 (还是分数形式)
m = (x%a)*b;
n = (y%b)*a;
Output(m, n);
}
}
return 0;
}