Epic - Decimal Number
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的更多相关文章
- 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 ...
- Epic - Desirable Number
A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You k ...
- 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 ...
- [LeetCode] Valid Number 验证数字
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
- 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 ...
- General Palindromic Number (进制)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- Friendly number
Friendly number Long numbers can be made to look nicer, so let’s write some code to do just that. Yo ...
- codeforces 464C. Substitutes in Number
题目链接 C. Substitutes in Number time limit per test 1 second memory limit per test 256 megabytes input ...
- Number 类型
Javascript使用IEEE -754格式存储整型和浮点型(有些语言称为双精度) 因为这种存储格式,所以javascript中有正的0和负的0 整型也可以存储八进制和十六制 八进制第一个数 ...
随机推荐
- Java日期转换SimpleDateFormat格式大全(转)
24小时制时间显示: public class Datetime { public static void main(String args[]){ java.util.Date current=ne ...
- leetcode:Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- 详解javascript中的call, apply
一些学js的同学一看到call, apply, 就蒙了, 感觉不好懂, 看的头大. 今天我们就一起来研究一下这2个东东.彻底弄清楚它们的用法. 定义: call, apply是函数的方法, 只有函数才 ...
- Enable test automation in Testlink
Enabling Test Automation in Testlink Step 1: Change config settings in testlink config file Edit c ...
- c#开源Excel操作库--NPOI
前言 以前也用C#操作过excel,用的是OleDb或者offic的com组件,但是总是非常的麻烦,依赖限制较多,所以果断寻找开源方案,JAVA上面已经有非常成熟的POI,就这样,找到了移.Net的移 ...
- Linux多线程(三)(同步互斥)
1. 线程的同步与互斥 1.1. 线程的互斥 在Posix Thread中定义了一套专门用于线程互斥的mutex函数.mutex是一种简单的加锁的方法来控制对共享资源的存取,这个互斥锁只有两种状态(上 ...
- LA 3213 Ancient Cipher
开始我理解错题意了,应该是这样理解的: 字符串1进行映射后可以做一个置换,若置换后与字符串2相同,也是输出YES的 比如ABCA 和 DDEF 因此我们需要做的就是统计有多少类字母,每一类有多少个,如 ...
- 15.Object-C--浅谈Foundation框架OC数组NSArray与NSMutableArray
昨天总结了一下NSString与NSMutableString,今天我在这里总结一下NSArray与NSMutableArray. NSArray数组是:不可变数组. nil 是数组元素结束的标记.O ...
- Calculate drive total/free/available space
using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Consol ...
- php最新出现的函数
1. 数据过滤函数 filter_var: filter_var — Filters a variable with a specified filter 过滤的类型有: Validate filt ...