列表

详情


NC51089. Fraction Comparision

描述

Bobo has two fractions and . 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.

*
*
* There are at most test cases.

输出描述

For each test case, print `=` if . Print `<` if . Print `>` otherwise.

示例1

输入:

1 2 1 1
1 1 1 2
1 1 1 1

输出:

<
>
=

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python(2.7.3) 解法, 执行用时: 338ms, 内存消耗: 3040K, 提交时间: 2020-06-30 13:23:31

import sys
for line in sys.stdin:
    x,a,y,b = map(int,line.split())
    if(x*b>y*a):
        print(">")
    elif x*b<y*a:
        print("<")
    else:
        print("=")

Ruby(2.4.2) 解法, 执行用时: 676ms, 内存消耗: 9040K, 提交时间: 2019-07-18 12:08:33

until STDIN.eof?
	x, a, y, b = gets.split.map(&:to_i)
	if x.to_r/a < y.to_r/b
		puts '<'
	elsif x.to_r/a > y.to_r/b
		puts '>'
	else
		puts '='
	end
end

Python3(3.5.2) 解法, 执行用时: 355ms, 内存消耗: 4308K, 提交时间: 2019-07-18 12:06:18

import sys
for s in sys.stdin:
	x, a, y, b = map(int, s.split())
	if b * x < a * y:
		print('<')
	elif b * x == a * y:
		print('=')
	else:
		print('>')

C++14(g++5.4) 解法, 执行用时: 119ms, 内存消耗: 6112K, 提交时间: 2019-08-17 22:26:11

#include<cstdio>
__int128 x,y,a,b;int main(){while(~scanf("%lld%d%lld%d",&x,&a,&y,&b))x*b-y*a>0?printf(">\n"):x*b-y*a?printf("<\n"):printf("=\n");}

上一题