鏈接: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;
}