链接:https://ac.nowcoder.com/acm/contest/881/J
来源:牛客网
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述
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
输出
复制
< > =
用java大数或者先相除比较整数部分,然后取模,这时分子分母都在1e9以内所以可以相乘比较大小
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3+9;
typedef long long ll;
const ll mod = 1e9+7;
int main(){
ll x,a,y,b;
while(~scanf("%lld%lld%lld%lld",&x,&a,&y,&b)){
ll k1=x/a,k2=y/b;
if(k1<k2)printf("<\n");
else if(k1>k2)printf(">\n");
else{
k1=x%a,k2=y%b;
if(k1*b<k2*a)printf("<\n");
else if(k1*b>k2*a)printf(">\n");
else printf("=\n");
}
}
return 0;
}