Fraction Comparision

Topic Link

The meaning of problems: input x, a, y, b find x / size and a y / b, the range of long long int

Idea: because not want to use precision, too much trouble, so used a clever method. First seek x / a and y / b shaping the size, if they are equal, then seek (x% a) * b and (Y% B ) A * size, particularly Why can contrast, are junior high school students.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main()
{
    ll x,y,a,b;
    while(scanf("%lld%lld%lld%lld",&x,&a,&y,&b)!=EOF)
    {
        ll z1=x/a;
        ll z2=y/b;
        if(z1>
        {z2)
            printf(">\n");
        }
        else if(z1<z2)
        {
            printf("<\n");
        }
        else
        {
            ll y1=x%a;
            ll y2=y%b;
            ll r1=y1*b;
            ll r2=y2*a;
            if(r1==r2)
            printf("=\n");
            if(r1>r2)
            printf(">\n");
            if(r1<r2)
            printf("<\n");
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/2462478392Lee/p/11279665.html