2 shunfurh shunfurh 于 2017.09.05 07:55 提问

Dead Fraction

Mike is frantically scrambling to finish his thesis at the last minute. He needs to assemble all his research notes into vaguely coherent form in the next 3 days. Unfortunately, he notices that he had been extremely sloppy in his calculations. Whenever he needed to perform arithmetic, he just plugged it into a calculator and scribbled down as much of the answer as he felt was relevant. Whenever a repeating fraction was displayed, Mike simply reccorded the first few digits followed by "...". For instance, instead of "1/3" he might have written down "0.3333...". Unfortunately, his results require exact fractions! He doesn't have time to redo every calculation, so he needs you to write a program (and FAST!) to automatically deduce the original fractions.

To make this tenable, he assumes that the original fraction is always the simplest one that produces the given sequence of digits; by simplest, he means the the one with smallest denominator. Also, he assumes that he did not neglect to write down important digits; no digit from the repeating portion of the decimal expansion was left unrecorded (even if this repeating portion was all zeroes).

Input

There are several test cases. For each test case there is one line of input of the form "0.dddd..." where dddd is a string of 1 to 9 digits, not all zero. A line containing 0 follows the last case.

Output

For each case, output the original fraction.

Note that an exact decimal fraction has two repeating expansions (e.g. 1/5 = 0.2000... = 0.19999...).

Sample Input

0.2...
0.20...
0.474612399...
0

Sample Output

2/9
1/5
1186531/2500000

2个回答

caozhy
caozhy   Ds   Rxr 2017.09.07 23:47
已采纳
shen_wei
shen_wei   Ds   Rxr 2017.09.05 15:31
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
POJ 1930 Dead Fraction
 Dead FractionTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 1198 Accepted: 354DescriptionMike is frantically scrambling to finish his thesis at the la
POJ 1930 Dead Fraction
poj1930 题目意思:给定一个无限循环小数,把它转换成分数。 这个需要一定姿势水平。。。纯循环9做分母,有几个循环数,就有几个9,例如0.3就是9分之3,0.654就是999分之654。。等等混循环把0.228转换成分数(8是循环节) =[(228/1000)+8/9000)] =228/(900+100)+8/9000 =[(228/900)-(228/9000)]+(8/9000)
POJ-1930 Dead Fraction(简单数论)
Mike is frantically scrambling to finish his thesis at the last minute. He needs to assemble all his research notes into vaguely coherent form in the next 3 days. Unfortunately, he notices that h
Dead Fraction POJ - 1930
Mike is frantically scrambling to finish his thesis at the last minute. He needs to assemble all his research notes into vaguely coherent form in the next 3 days. Unfortunately, he notices that he had
Dead Fraction(辗转相除法)
原题链接Dead Fraction Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2668 Accepted: 867 DescriptionMike is frantically scrambling to finish his thesis at the last minute. He needs t
POJ1930 Dead Fraction 数学
这题是个数学题,就是gei
FOJ 1006 Dead Fraction
题目大意:给出一个循环小数(循环位未知),让你转化为一个分母最小的分数。 百度百科的公式是这么告诉我们的: 用9和0做分母,首先有一个循环节有几位数字就几个9,接着有几个没加入循环的数就加几个0,再用第二个循环节以前的小数部分组成的数与小数部分中不循环部分组成的数的差做分子,比如0.43,3的循环,有一位数没加入循环,就在9后面加一个0做分母,再用43减4做分子,得 90分之39,0.14
Dead Fraction(poj1930)
Mike is frantically scrambling to finish his thesis at the last minute. He needs to assemble all his research notes into vaguely coherent form in the next 3 days. Unfortunately, he notices that he had...
POJ 1930 Dead Fraction 笔记
<span title="Description ">描述 迈克疯狂地在最后一分钟完成他的论文。他需要在接下来的3天内将所有研究笔记以模糊一致的形式汇编。不幸的是,他注意到他在计算时非常吝啬。每当他需要执行算术时,他只是把它插入一个计算器,并潦草地写了许多答案,因为他认为相关。每当重复分数显示,麦克简单记录的前几个数字后跟“...”。例如,而不是“1/3”,他可能写下“0.3333 .
POJ 1930 Dead Fraction 数论
别人说这是小学奥数水平的题目,orz,作者受到了极大的打击。 如果是用笔写的话相信很多人都能将循环小数化成分数。 来个例子吧:0.333.....怎么化成分数呢? 设 x = 0.333...... 10x = 3.33...... 10x - x = 3 9x = 3 x = 1 / 3 和这个思路类似,对于一般情况,我们可以推导出一个公式(推导出了公式才方便编程)。 引用别人