Cattle off more school first

Fraction Comparision

Time limit: C / C ++ 2 seconds and 4 seconds languages other
space restrictions: C / C ++ 524288K, other languages 1048576K
64bit the IO the Format: LLD%

Title Description

Bobo has two fractions xaxa and ybyb. He wants to compare them. Find the result.

Enter a description:

The input consists of several test cases and is terminated by end-of-file.

Each test case contains four integers x, a, y, b.

* 0x,y10180≤x,y≤1018
* 1a,b1091≤a,b≤109
* There are at most 105105 test cases.

Output Description:

For each test case, print `=` if xa=ybxa=yb. Print `<` if xa<ybxa<yb. Print `>` otherwise.
Example 1

Entry

copy
1 2 1 1
1 1 1 2
1 1 1 1

Export

copy
< 
> 
= 

The AC codes:

#include <iostream>
using namespace std;
int main()
{
long long x, a, y, b;
while(cin >> x >> a >> y >> b)
{
__int128 l = (__int128)x*b;
__int128 r = (__int128)y*a;
if(l>r) cout << ">" << endl;
else if(l<r) cout << "<" << endl;
else cout << "=" << endl;
}
return 0;
}

 

Source Gangster blog: https://www.cnblogs.com/ECJTUACM-873284962/p/9198885.html

 

The official GCC provides two 128-bit integer types, namely __int128_t and __uint128_t, are used to declare signed integer variable and an unsigned integer variables.

 This function can not be used cout large integer output value, you need to customize the output function.

 void myitoa(__int128_t v, char* s)  {  char temp;  int i=0, j;   while(v >0) {  s[i++] = v % 10 + '0';  v /= 10;   }  s[i] = '\0';   j=0 ; I - ; the while ( J < I ) { TEMP = S [ J ]; S [ J ] = S [ I ]; S [ I ] = TEMP ; J ++ ; I - ; } } A + B Tarsus read template                


 1 #include <bits/stdc++.h>  2 using namespace std;  3 inline __int128 read()  4 {  5 __int128 x=0,f=1;  6 char ch=getchar();  7 while(ch<'0'||ch>'9')  8  {  9 if(ch=='-') 10 f=-1; 11 ch=getchar(); 12  } 13 while(ch>='0'&&ch<='9') 14  { 15 x=x*10+ch-'0'; 16 ch=getchar(); 17  } 18 return x*f; 19 } 20 21 inline void write(__int128 x) 22 { 23 if(x<0) 24  { 25 putchar('-'); 26 x=-x; 27  } 28 if(x>9) 29 write(x/10); 30 putchar(x%10+'0'); 31 } 32 33 int main() 34 { 35 __int128 a = read(); 36 __int128 b = read(); 37 write(a + b); 38 return 0; 39 }
 

Guess you like

Origin www.cnblogs.com/zhenzheng/p/11220248.html