链接:https://ac.nowcoder.com/acm/contest/8409/F
来源:牛客网
链接:https://ac.nowcoder.com/acm/contest/8409/F
来源:牛客网
Bobo has two fractions xa\frac{x}{a}ax and yb\frac{y}{b}by. 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 \leq x, y \leq 10^{18}0≤x,y≤1018
- 1≤a,b≤1091 \leq a, b \leq 10^91≤a,b≤109
- There are at most 10510^5105 test cases.
输出描述:
For each test case, print =
if x/a = y/b. Print <
if x/a < y/b. Print >
otherwise.
示例1
输入
复制
1 2 1 1
1 1 1 2
1 1 1 1
输出
复制
<
=
>
思路:首先,做这个题的时候,不能直接除,会爆double,也不能交叉相乘,会爆long long ,那么就只能先比较整数部分,再看真分数部分,真分数的分子和分母都在10的9次方之内,所以交叉相乘不会爆long long ,直接比较就可以啦!
#include <bits/stdc++.h>
using namespace std;
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)
{
printf(">\n");
}
else if(m<n)
{
printf("<\n");
}
else//如果整数部分相等,再看小数部分
{
m=(x%a)*b;
n=(y%b)*a;
if(m>n)
{
printf(">\n");
}
else if(m<n)
{
printf("<\n");
}
else
{
printf("=\n");
}
}
}
return 0;
}