usaco 2.4 fractions to decimails
来源:互联网 发布:华大基因 大数据 编辑:程序博客网 时间:2024/04/30 16:11
usaco 2.4 fractions to decimails
写一个程序,输入一个形如N/D的分数(N是分子,D是分母),输出它的小数形式。如果小数有循环节的话,把循环节放在一对圆括号中。
例如,
1/3 =0.33333333 写成0.(3),
41/333 = 0.123123123... 写成0.(123),
用xxx.0 等表示整数。
典型的转化例子:
1/3 = 0.(3)22/5 = 4.41/7 = 0.(142857)2/2 = 1.03/8 = 0.37545/56 = 0.803(571428)
SAMPLE INPUT
45 56
SAMPLE OUTPUT
0.803(571428)
本题模拟加哈奇表优化,就可以解出来,但是为了最求短时间,和编译复杂程度。我就不用哈奇表,因为余数只可能出现一个,就直接用一个桶就好了。当那个位有数就可以结束了,然后就是用字符串输出(这个看了一下题解),也会简单点。
var n,d,i:longint; s,ans:ansistring; pos:array[0..1000000] of longint;begin assign(input,'fracdec.in'); reset(input); assign(output,'fracdec.out'); rewrite(output); fillchar(pos,sizeof(pos),0); read(n,d); str(n div d,ans); ans:=ans+'.'; n:=n mod d*10; If n=0 then ans:=ans+'0' else repeat pos[n]:=length(ans); str(n div d,s); ans:=ans+s; n:=n mod d*10; if pos[n]<>0 then ans:=copy(ans,1,pos[n])+'('+copy(ans,pos[n]+1,length(ans)-pos[n])+')' until (n=0) or (pos[n]<>0); for i:=1 to length(ans) do begin write(ans[i]); if i mod 76=0 then writeln end; writeln; close(input); close(output)end.
4 0
- usaco 2.4 fractions to decimails
- USACO--2.4Fractions to Decimals
- USACO 2.4 Fractions to Decimals
- USACO 2.4.5 Fractions to Decimals
- USACO 2.4.5 Fractions to Decimals
- USACO 2.4 Fractions to Decimals (fracdec)
- USACO 2.4 Fractions to Decimals (模拟)
- USACO Section 2.4 Fractions to Decimals
- USACO Fractions to Decimals
- USACO Fractions to Decimals
- usaco Fractions to Decimals
- USACO:Fractions to Decimals
- USACO-Fractions to Decimals
- USACO-Fractions to Decimals
- 【模拟】【USACO】Fractions to Decimals
- usaco Chapter 2 section 2.4 Fractions to Decimals
- USACO section 2.4 Fractions to Decimals(小数处理)
- USACO-Section 2.4 Fractions to Decimals(模拟)
- C++ 访问权限
- LeetCode之操作两个数相除DivideTwoIntegers
- jQuery html() 方法
- oracle不提供CREATE TABLE IF NOT EXIST方式创建表
- UML类图与类的关系
- usaco 2.4 fractions to decimails
- titanic survival 2
- js注册在标签上的点击事件
- Ordered dithering
- 多余元素删除之移位算法
- web安全(入门篇)
- 伪静态配置开启
- linux下查看所有登录用户的历史操作命令
- Flex 布局教程:语法篇