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. Spring AOP 创建切面

        增强被织入到目标类的所有方法中,但是如果需要有选择性的织入到目标类某些特定的方法中时,就需要使用切点进行目标连接点的定位.增强提供了连接点方位信息:如织入到方法前面.后面等,而切点进一步描述织 ...

  2. MongoDB安装Windows服务

    由于官方下载较慢.这里提供一个个人百度共享网盘地址: http://pan.baidu.com/s/1mhHW0nI mongodb-win32-x86_64-3.2.3 使用以下命令将MongoDB ...

  3. C语言输出当前日期和时间

    #include <stdio.h> #include <time.h> char* asctime2(const struct tm *timeptr) { static c ...

  4. Java 数据类型转换

    int iValue = new Integer(strValue).intValue();String str = intObj.toString();int number = Integer.pa ...

  5. 1427. SMS(DP)

    1427 题意不太好理解 其它没什么 细心啊 细心 一个0写成了1 WA半天 以每个字符是以第一种方式还是第二种方式来D #include <iostream> #include<c ...

  6. Velocity模板中的注释

    Velocity ——VTL模板中的注释 注释允许在模板中包含描述文字,而这些文字不会被放置到模板引擎的输出中.注释是一种有效的提醒自己和向别人解释你的VTL语句要做什么事情的方法.你也可以把注释用来 ...

  7. Swustoj题目征集计划

    SWUST OJ题目征集计划   鉴于SWUST OJ长时间没有新题添加,题目数量和类型有限,同时也为加强同学们之间的算法交流,享受互相出题AC的乐趣,提高算法水平,现在启动题目征集计划啦~ 当你遇到 ...

  8. chrome浏览器下禁制 textarea改变大小; Jquery的textareaCounter插件控制textarea输入的字符数量

    给  textarea 添加一个css 样式即可 resize: none;   用Jquery的插件控制textarea输入的字符数量 一:引用Jquery脚本,并引入 textareaCounte ...

  9. UIView的user Interaction Enabled属性

    A Boolean value that determines whether user events are ignored and removed from the event queue. 译: ...

  10. Hibernate-Native SQL

    1.标量(值)查询: sess.createSQLQuery("SELECT * FROM CATS").list(); sess.createSQLQuery("SEL ...