usaco-Section 2.4-Fractions to Decimals

本文提供了一个程序实现,用于将分数转换为其十进制表示,并且能够标识出任何重复的小数部分,使用括号表示循环节。通过实例展示了不同分数的转换过程及结果呈现。
Fractions to Decimals

Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is denoted as 0.(123). Use xxx.0 to denote an integer. Typical conversions are:

1/3     =  0.(3)
22/5    =  4.4
1/7     =  0.(142857)
2/2     =  1.0
3/8     =  0.375
45/56   =  0.803(571428)

PROGRAM NAME: fracdec

INPUT FORMAT

A single line with two space separated integers, N and D, 1 <= N,D <= 100000.

SAMPLE INPUT (file fracdec.in)

45 56

OUTPUT FORMAT

The decimal expansion, as detailed above. If the expansion exceeds 76 characters in length, print it on multiple lines with 76 characters per line.

SAMPLE OUTPUT (file fracdec.out)

0.803(571428)

此题的思想和高精除数有雷同之处,附赠一小段代码:

while(n!=0){
  n*=10;
  dp[++tot]=n/mod;
  n%=mod;
  if(vist[n]==0){
    vist[n]=1;
    g[n]=tot;
  }else{
    pos=g[n];
    biaoji=1;
    break;
  }

}

核心思想就是寻找循环节,注意题目的要求

转载于:https://www.cnblogs.com/buffms/p/5155625.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值