Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places are allowed. Theoutput should be an irreducible fraction. E.g.: If the user enters 0.35,the irreducible fraction will be 7/20.

等于找与10000的公约数

def fraction(d)
x = d*10000
gcd = findgcd(x,10000)
(x/gcd).to_i.to_s + '/' + (10000/gcd).to_i.to_s
end def findgcd(a,b)
return a if b == 0
findgcd(b,a%b)
end

Epic - Decimal Number的更多相关文章

  1. Java – Convert IP address to Decimal Number

    In this tutorial, we show you how to convert an IP address to its decimal equivalent in Java, and vi ...

  2. Epic - Desirable Number

    A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You k ...

  3. Epic - Seed Number

    Find the seed of a number. Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible ...

  4. [LeetCode] Valid Number 验证数字

    Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...

  5. Codeforces Round #265 (Div. 1) C. Substitutes in Number dp

    题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...

  6. General Palindromic Number (进制)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  7. Friendly number

    Friendly number Long numbers can be made to look nicer, so let’s write some code to do just that. Yo ...

  8. codeforces 464C. Substitutes in Number

    题目链接 C. Substitutes in Number time limit per test 1 second memory limit per test 256 megabytes input ...

  9. Number 类型

    Javascript使用IEEE -754格式存储整型和浮点型(有些语言称为双精度) 因为这种存储格式,所以javascript中有正的0和负的0   整型也可以存储八进制和十六制   八进制第一个数 ...

随机推荐

  1. c++ 字符串函数用法举例

    1. substr() 2. replace() 例子:split() 字符串切割: substr 函数原型: , size_t n = npos ) const; 解释:抽取字符串中从pos(默认为 ...

  2. linux 命令案例学习——文件搜索

    两个搜索文件的工具 locate  ——仅仅通过文件名查找文件 find     ——依据文件的各种属性在既定目录(包括子目录)里查找 一个通常与文件搜索命令一起使用.处理搜索结果文件列表的命令 xa ...

  3. mysql 日期

    数据类型 数据类型 格式 date YYYY-MM-DD datetime YYYY-MM-DD HH:MM:SS timestamp YYYY-MM-DD HH:MM:SS year YYYY 或 ...

  4. POJ 2689 Prime Distance (素数+两次筛选)

    题目地址:http://poj.org/problem?id=2689 题意:给你一个不超过1000000的区间L-R,要你求出区间内相邻素数差的最大最小值,输出相邻素数. AC代码: #includ ...

  5. oracle数据库sql的基本使用

    整理了下关于oracle数据库中SQL的基本使用语句,整理如下,方便记忆. oracle的基本术语 数据字典,数据库元数据信息的数据字典表和用户可以读取的数据字典视图组成.存放oracle数据库所用的 ...

  6. git 创建branch分支【转】

    转自:http://www.cnblogs.com/jackluo/p/3499731.html 开发者user1 负责用getopt 进行命令解析的功能,因为这个功能用到getopt 函数,于是将这 ...

  7. Java异常 —— java.lang.NoClassDefFoundError

    一直使用 Eclipse 来开发 Java . 现学习 Maven,在 cmd 下使用 Java ,出现了这样的异常:Exception in thread "main" java ...

  8. Java中什么时候使用构造方法

    JAVA是面向对象的语言,面向对象不是这么直接简单,它的设计思想就是要代码重用.即我以前干过类似的事,那么我找出以前可以用到的代码,完成一部分.以前没有的我重新写.这样就有了类.有了类,就是有了可以重 ...

  9. poj - 1258 Agri-Net (最小生成树)

    http://poj.org/problem?id=1258 FJ为了竞选市长,承诺为这个地区的所有农场联网,为了减少花费,希望所需光纤越少越好,给定每两个农场的花费,求出最小花费. 最小生成树. # ...

  10. MTK平台缩写

    HSPA:High Speed Packet Access smartphone application processor,高速分组接入的智能手机应用程序处理器 META mode:Mobile E ...