RecurringNumbers (google code jam china 1000分真题)
来源:互联网 发布:php初学者项目 编辑:程序博客网 时间:2024/05/16 16:06
Problem Statement
A rational number is defined as a/b, where a and b are integers, and b is greater than 0. Furthermore, a rational number can be written as a decimal that has a group of digits that repeat indefinitely. A common method of writing groups of repeating digits is to place them inside parentheses like 2.85(23) = 2.852323 ... 23...
Given a decimal representation of a rational number in decimalNumber, convert it to a fraction formatted as "numerator/denominator", where both numerator and denominator are integers. The fraction must be reduced. In other words, the denominator must be as small as possible, but greater than zero.
Definition
Class: RecurringNumbers Method: convertToFraction Parameters: String Returns: String Method signature: String convertToFraction(String decimalNumber) (be sure your method is public)Constraints
- decimalNumber will have between 3 and 10 characters inclusive. - decimalNumber will contain only characters '0' - '9', '.', '(' and ')'. - The second character in decimalNumber will always be '.'. - There will be at most one '(' and ')' in decimalNumber. - '(' in decimalNumber will be followed by one or more digits ('0' - '9'), followed by ')'. - ')' in decimalNumber will not be followed by any other character.Examples
0)"0.(3)"
Returns: "1/3"0.(3) = 0.333... = 1/3 1)
"1.3125"
Returns: "21/16"Note there are no recurring digits here, although we could write it as 1.3125(0) or 1.3124(9). 2)
"2.85(23)"
Returns: "14119/4950"2.85(23) = 2.852323... = 285/100 + 23/9900 = 28238/9900 = 14119/4950. Make sure to reduce the fraction, as shown in the final step. 3)
"9.123(456)"
Returns: "3038111/333000"4)
"0.111(1)"
Returns: "1/9"5)
"3.(000)"
Returns: "3/1"
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
- RecurringNumbers (google code jam china 1000分真题)
- RecurringNumbers (code jam china 1000分真题) (第二轮淘汰赛)
- Google China Code Jam
- Google Code Jam Great China Round A
- Google Code Jam Great China Test Round 2013
- FactorialSystem (code jam china round2 300分真题) (第二轮淘汰赛)
- Google Code Jam 2006
- Google Code Jam
- Google Code Jam 130914
- Google Code Jam 2015
- Google Code Jam 2015
- 2016 google code jam
- Google code jam
- Google Code Jam预选赛完成.
- My Google Code Jam 2010
- Google Code Jam 2011 (Qualification)
- Google Code Jam 2013 - Bullseye
- 2013 google code jam Lawnmower
- 软件工程师好了歌
- 我的Nokia6070
- 菜鸟的日子1
- 架构师已死
- 给一段软件公司求职对白,供想要求职的软件开发人员参考
- RecurringNumbers (google code jam china 1000分真题)
- 开博了
- ASP.NET初体验 测试示例
- 关于ListCtrl,RichEdit和程序框架的一些东东
- 程序员的灯下黑:坚持和良好心态近乎道
- 软件文档--扬弃还是传承 (原文最终修订于 2006-04-12,上午12:41:14)
- CFont的问题和一个郁闷我两天的Commobox背景色的问题
- 搜索通配符字符的说明
- Windows消息大全