Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > RecurringNumbers (google code jam china 1000分真题)
【标  题】:RecurringNumbers (google code jam china 1000分真题)
【关键字】:RecurringNumbers,google,code,jam,china,1000
【来  源】:http://blog.csdn.net/wang_junjie/archive/2006/09/26/1287925.aspx

RecurringNumbers (google code jam china 1000分真题)

Your Ad Here  

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.

求集合的幂集:【上一篇】
关于C++0x内存模型和序列点的一些思考:【下一篇】
【相关文章】
  • The Google Story
  • ChinaitLib Linux实战工程师介绍
  • 将给定的字符串里面的每个字符左移N位(TopCoder)
  • 针对C程序员的TopCoder C++
  • 从ASCII到Unicode(UTF-8)
  • kunth~s desktop fvwmbutton code
  • google趋势服务
  • Windows环境下Unicode编程总结
  • Security Code Guidelines
  • Code::Blocks 最新的FREE C++ IDE介绍[转载]
  • 【随机文章】
  • .net学习:WSE使用总结
  • 字符处理函数
  • sb 八月份的时候梦到SB 而找了她的图片 做了她的盔甲
  • 完整的访问统计程序(三 应用篇)
  • ESQL编程使用说明
  • 用asp怎样编写文档搜索页面(4)
  • ADO.NET 2.0 中的ConnectionStringBuilder
  • 关注J2ME WTK2.2新特性
  • 在SUN工作站上安装RTL8139网卡
  • 分析内核对gzip压缩文件进行解压的方法
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.