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
时间: 2024-08-26 15:41:46

Epic - Decimal Number的相关文章

Epic - Desirable Number

A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You know that your rivalhas a strictly numeric password that is 'desirable'. Your close ally has givenyou the number of digits (N) in your rival's password. WAP

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 seed for a given number. 辗转相除法,由性质可利用 sqrt(num) <= seed_number <= num/2 缩小范围. def seed_number(num) seed = Math.sqrt(num).to_i while seed <= num /

1019. General Palindromic Number (20)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

A1019. General Palindromic Number (20)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

1019. General Palindromic Number

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

pat1019. General Palindromic Number (20)

1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic

PAT1019. General Palindromic Number

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

General Palindromic Number (进制)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

Codeforces 464 C. Substitutes in Number 动态规划法题解

C. Substitutes in Number time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew mult