链接: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 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
输出
< > =
#include <stdio.h>
#include <stdlib.h>
int main()
{
long long int x,y,a,b;
while(scanf("%lld %lld %lld %lld",&x,&a,&y,&b)!=EOF)
{
long long int q,p,u,v;
u=x/a;
v=y/b;
if(u>v)
{
printf(">\n");
}
else if(u<v)
{
printf("<\n");
}
else
{
if(x<a)
{
u=a/x;
v=b/y;
p=a%x*y;
q=b%y*x;
if(u<v)
printf(">\n");
else if(u>v)
printf("<\n");
else
{
if(p<q)
printf(">\n");
else if(p>q)
printf("<\n");
else
printf("=\n");
}
}
else
{
p=y%b*a;
q=x%a*b;
if(q>p)
{
printf(">\n");
}
else if(q<p)
{
printf("<\n");
}
else
printf("=\n");
}
}
}
return 0;
}