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. Database Corruption ->> Fix Database In Suspect State

    昨天在工作中遇到一个情况,就是Development环境中的某台服务器上的某个数据库进入了Suspect状态.以前看书倒是知道说这个状态,不过实际工作当中从来没有遇到过.那么一些背景情况是这样的. 环 ...

  2. [转载]TexturePacker 如何使用自带的加密功能及在cocos2dx中的使用

    在cocos2dx中使用纹理图集是非常节省资源的,在这里推荐 TexturePacker,而且 TexturePacker工具的加密接口也非常的好用,下面就来介绍一下... TexturePacker ...

  3. oracle11g OEM无法连接到数据库实例解决办法

    我的电脑是32位的win7家庭版系统,那么这样的系统能不能装上oracle呢?能的!就是可能会出错,在装oracle时,每个人遇到的问题都不同,有的人装了双系统,有的人重做了系统,真心酸,先让电脑断网 ...

  4. Fedora 15 KDE中如何打开software management及如何应用

    Fedora 15 KDE中如何打开software management级如何应用 software management中有转载和卸载软件(Get and remove software)的功能 ...

  5. IRQ和FIQ中断的区别【转】

    转自:http://blog.csdn.net/michaelcao1980/article/details/19542039 FIQ和IRQ是两种不同类型的中断,ARM为了支持这两种不同的中断,提供 ...

  6. 第三方登录(1)OAuth(开放授权)简介及授权过程

    3个角色:服务方,开发者,用户 a.用户在第在服务注册填写个人信息, b.服务方开放OAuth, c.开发者在服务方申请第3方登录,在程序中得到令牌后,经用户同意,可得到用户的个人信息. OAuth ...

  7. HDU 4757 Tree(可持久化trie)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4757 题意:给出一棵树,节点有权值.每次询问x到y的路径上与z抑或的最大值. 思路:可持久化trie. ...

  8. 浅析JavaScript引用类型之--Object、Array

    1.Object类型 对象是某个特定引用类型的实例,新对象有两种创建方式: i.使用new操作符调用构造函数来创建. var person = new Object(); person.name = ...

  9. cut命令如何截取以空格隔开的字段

    你的文件分隔符恐怕不止一个空格(一定的who生成的): 用awk: awk '{print $2}' file 一定要用cut的话: cat file|tr -s ' '|cut -d' ' -f2 ...

  10. R语言,NA,NAN

    好莫名其妙的结果 is.na() #NA得不到的值is.nan() #NAN不可能的值is.infinite() #无穷的 x1<-NA x2<-0/0x3<-1/0 is.na(x ...