問題一覧 > 通常問題

No.750 Frac #1

レベル : / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 454
作問者 : Mcpu3 / テスター : ciel
お気に入りにしたユーザー ProblemId : 2455 / 自分の提出
問題文最終更新日: 2019-07-27 01:21:41
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 203 (順位表) の他の問題:

Problem Statement

You are given $n$ distinct fractions in the following format, each of which is an irreducible fraction, a fraction whose numerator is $0$, or a fraction whose denominator is $1$.

$\Large{ \cfrac{ A_1 }{ B_1 } , \ \cfrac{ A_2 }{ B_2 } , \ \cdots \cfrac{ A_n }{ B_n } }$

Sort the given fractions in descending order.

Input

$n$
$\! \begin {align} A_1 & \ B_1 \\ A_2 & \ B_2 \\ & \vdots \\ A_n & \ B_n \end {align}$

The input consists of integers satisfying the following constraints.

  • $1 \leq n \leq 10$
  • $-9 \leq A_i \leq 9$
  • $1 \leq B_i \leq 9$
  • $( A_i , \ B_i ) \neq ( A_j , \ B_j )$ when $i \neq j$
  • Here, $1 \leq i , \ j \leq n$.

    Output

    Output the given fractions in descending order, separated by newlines, each in the format "numerator denominator".

    Sample

    Sample 1
    Input
    6
    4 5
    3 7
    3 4
    -2 3
    9 1
    3 8
    Output
    9 1
    4 5
    3 4
    3 7
    3 8
    -2 3

    $\Large{ \cfrac{ 9 }{ 1 } \gt \cfrac{ 4 }{ 5 } \gt \cfrac{ 3 }{ 4 } \gt \cfrac{ 3 }{ 7 } \gt \cfrac{ 3 }{ 8 } \gt \cfrac{ -2 }{ 3 } }$

    Sample 2
    Input
    3
    3 7
    1 1
    5 3
    Output
    5 3
    1 1
    3 7

    $\Large{ \cfrac{ 5 }{ 3 } \gt \cfrac{ 1 }{ 1 } \gt \cfrac{ 3 }{ 7 } }$

    Sample 3
    Input
    6
    1 1
    7 4
    0 5
    1 3
    -8 9
    5 1
    Output
    5 1
    7 4
    1 1
    1 3
    0 5
    -8 9

    $\Large{ \cfrac{ 5 }{ 1 } \gt \cfrac{ 7 }{ 4 } \gt \cfrac{ 1 }{ 1 } \gt \cfrac{ 1 }{ 3 } \gt \cfrac{ 0 }{ 5 } \gt \cfrac{ -8 }{ 9 } }$

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。