链接:J-Fraction Comparision_2022牛客五一集训派对day4 (nowcoder.com)
来源:牛客网
题目描述
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 xa=yb\frac{x}{a} = \frac{y}{b}ax=by. Print `<` if xa<yb\frac{x}{a} < \frac{y}{b}ax<by. Print `>` otherwise.
示例1
输入
1 2 1 1 1 1 1 2 1 1 1 1
输出
< > =
题意:比较x/a和y/b的大小
思路:本体数据范围较大,直接除和相乘都会超范围,所以先直接用longlong除出整数比,如果相等再比较他们的小数。(解题的时候属实是脑子短路了,用了一系列花里胡哨的想法,然后速wa)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll x,y,a,b,x1,y1;
while(scanf("%lld %lld %lld %lld",&x,&a,&y,&b)!=EOF)
{
x1=(x/a);
y1=(y/b);
if(x1==y1)
{
ll x2=(x%a)*b;
ll y2=(y%b)*a;
if(x2==y2)
cout<<"="<<endl;
else if(x2>y2)
cout<<">"<<endl;
else
cout<<"<"<<endl;
}
else if(x1>y1)
cout<<">"<<endl;
else
cout<<"<"<<endl;
}
}