zoukankan      html  css  js  c++  java
  • 2.1.2 Ordered Fractions

    Ordered Fractions

    Consider the set of all reduced fractions between 0 and 1 inclusive with denominators less than or equal to N.

    Here is the set when N = 5:

    0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1
    

    Write a program that, given an integer N between 1 and 160 inclusive, prints the fractions in order of increasing magnitude.

    PROGRAM NAME: frac1

    INPUT FORMAT

    One line with a single integer N.

    SAMPLE INPUT (file frac1.in)

    5
    

    OUTPUT FORMAT

    One fraction per line, sorted in order of magnitude.

    SAMPLE OUTPUT (file frac1.out)

    0/1
    1/5
    1/4
    1/3
    2/5
    1/2
    3/5
    2/3
    3/4
    4/5
    1/1
    {
    ID: makeeca1
    PROG: frac1
    LANG: PASCAL
    }
    
    var n:longint;
    procedure mid(a,b,c,d:longint);
    begin
      if b+d>n then exit;
      mid(a,b,a+c,b+d);
      writeln(a+c,'/',b+d);
      mid(a+c,b+d,c,d);
    end;
    begin
      assign(input,'frac1.in');reset(input);
      assign(output,'frac1.out');rewrite(output);
      readln(n);
      writeln('0/1');
      mid(0,1,1,1);
      writeln('1/1');
      close(input);close(output);
    end.
     
  • 相关阅读:
    js日期 操作
    c# 调用c++ dll
    多维数组与交错数组的转换
    c++多态
    c++ 指向类成员函数的函数指针
    c++虚析构函数的使用及其注意点
    c++模板实现 linq
    Php 常用类
    Php ORM 对象关系映射
    Php OpenID
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274548.html
Copyright © 2011-2022 走看看