uva 202求循环小数
来源:互联网 发布:tomcat端口有哪些 编辑:程序博客网 时间:2024/04/30 15:34
The decimal expansion of the fraction 1/33 is , wherethe is used to indicate that the cycle 03 repeatsindefinitely with no intervening digits. In fact, the decimal expansion ofevery rational number (fraction) has arepeating cycle as opposed to decimal expansions of irrational numbers,which have no such repeating cycles.
Examples of decimal expansions of rational numbers and their repeating cyclesare shown below. Here, we useparentheses to enclose the repeating cycle rather than place a bar overthe cycle.
Write a program that reads numerators and denominators of fractions anddetermines their repeating cycles.
Forthe purposes of this problem, define a repeating cycle of a fraction to bethe first minimal length string of digits tothe right of the decimal that repeats indefinitely with no intervening digits.Thus for example, the repeating cycle ofthe fraction 1/250 is 0, which begins at position 4 (as opposed to 0 whichbegins at positions 1 or 2 and as opposedto 00 which begins at positions 1 or 4).
Input
Each line of the input file consists of an integer numerator, which isnonnegative, followed by an integerdenominator, which is positive. None of the input integers exceeds 3000.End-of-file indicates the end of input.
Output
For each line of input, print the fraction, its decimal expansion through thefirst occurrence of the cycle to the rightof the decimal or 50 decimal places (whichever comes first), and the lengthof the entire repeating cycle.
In writingthe decimal expansion, enclose the repeating cycle in parentheses when possible.If the entire repeating cycle doesnot occur within the first 50 places, place a left parenthesis where thecycle begins - it will begin within the first 50places - and place ``...)" after the 50th digit.
Print a blank line after every test case.
Sample Input
76 255 431 397
Sample Output
76/25 = 3.04(0) 1 = number of digits in repeating cycle5/43 = 0.(116279069767441860465) 21 = number of digits in repeating cycle1/397 = 0.(00251889168765743073047858942065491183879093198992...) 99 = number of digits in repeating cycle
循环小数,仔细就行。下面代码主干是对的,不过最后的输出格式被我后来存到自己u盘里时改了-.-改回来其实挺容易的:
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int main(){ int a,b,i,k; while(cin>>a>>b) { int flag=1,a0=a; int yu[3000],shang[3000]; for(i=0;1;i++) { shang[i]=a/b; yu[i]=a-shang[i]*b; if(yu[i]==0) { k=i; i++; shang[i]=0; yu[i]=0; break; } for(k=0;k<i;k++) if(yu[k]==yu[i]) { flag=0; break; } if(flag==0)break; a=yu[i]*10; } cout<<a0<<'/'<<b<<" = "<<shang[0]<<'.'; for(int x=1;x<=k;x++) cout<<shang[x]; cout<<'(';int x; for(x=k+1;x<=i;x++) cout<<shang[x]; cout<<')'<<endl; cout<<"循环节长度是"<<i-k<<endl<<endl; } return 0;}
- uva 202求循环小数
- 循环小数(uva-202)
- UVA 202 循环小数
- UVA 202 循环小数
- UVA 202 循环小数
- UVA-3.8-循环小数-202
- UVA 202 循环小数
- UVa 202 循环小数节
- UVA 202 有理数化为循环小数求循环节 UVA 11809 对数处理数据
- 题解:循环小数(UVa 202)
- 求循环小数
- UVa 202 Repeating Decimals(循环小数)
- UVa 202 Repeating Decimals(循环小数)
- UVA 202 - Repeating Decimals【循环小数循环节】
- UVA 202 循环小数百度解法 自己不会。
- 3. 求循环小数
- 小紫书 习题 3-8(UVA 202) 循环小数(Repeating Decimals)
- UVA 202 - Repeating Decimals(循环小数循环节)
- Java回忆录(三)-------流程控制
- MySQL中concat函数(连接字符串)
- 建食堂
- JS 整型,浮点型转化为字符型
- zthread学习 三 使用Executor器来执行线程
- uva 202求循环小数
- C++中为什么要将析构函数设为virtual
- zthread学习 实例四 让步、休眠、优先级
- [Python]网络爬虫(一):抓取网页的含义和URL基本构成
- Matlab中一个很有用的函数:regionprops
- zthread学习 实例五 非任务对象的生存期
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- JSP页面显示倒计时
- 简明Vim练级攻略