UVa 202, Repeating Decimals
来源:互联网 发布:项目开发计划软件 编辑:程序博客网 时间:2024/05/01 11:02
Problem
传送门
Mean1
输入整数a和b(0≤a≤3000,1≤b≤3000),输出a/b的循环小数表示以及循环节长度。例如a=5,b=43,小数表示为0.(116279069767447860465),循环节长度为21。
Analysis
预处理整数位后反复乘除计算小数位,发现循环节后终止。
注意各个小细节的处理。详见代码。
Code
#include<cstdio>#include<map>using namespace std;int n,m,u[3000];int main(){ while(~scanf("%d%d",&n,&m)){ map<int,int>place; printf("%d/%d = %d.",n,m,n/m); int i=0; place[n%m]=0; for(;;){ n=n%m*10; u[++i]=n/m; if(!place.count(n%=m)) place[n]=i; else break; } for(int j=1;j<=place[n];j++) printf("%d",u[j]); printf("("); if(i-place[n]>50){ for(int j=1;j<=50;j++) printf("%d",u[j+place[n]]); printf("..."); }else for(int j=place[n]+1;j<=i;j++) printf("%d",u[j]); printf(")\n %d = number of digits in repeating cycle\n\n",i-place[n]); } return 0;}
- 来自刘汝佳《算法竞赛入门经典(第2版)》 ↩
0 0
- UVa 202 - Repeating Decimals
- UVa 202 - Repeating Decimals
- UVa 202 - Repeating Decimals
- UVa 202 Repeating Decimals
- Uva 202 Repeating Decimals
- UVA - 202 Repeating Decimals
- UVa 202 Repeating Decimals
- UVa-202 - Repeating Decimals
- UVa 202 Repeating Decimals
- UVa 202 Repeating Decimals
- UVA - 202 Repeating Decimals
- Uva - 202 - Repeating Decimals
- UVA - 202 Repeating Decimals
- [UVA 202]Repeating Decimals
- UVa 202 Repeating Decimals
- uva 202 Repeating Decimals
- UVa 202 - Repeating Decimals
- UVa 202, Repeating Decimals
- 深入理解Java:注解(Annotation)自定义注解入门
- Java中两种多线程实现方式的区别
- 静态变量和实例变量的区别?
- 慢跑鞋 zocm txks eett
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- UVa 202, Repeating Decimals
- 使用二分查找算法在数组查找随机生成的key对应的值
- 驾照相关:中华人民共和国公安部第123号令
- 1064. Complete Binary Search Tree (30)
- 提高代码质量:如何编写函数
- Dmaven.multiModuleProjectDirectory system property is not set
- 如何确定计算机是32位还是64位
- JAVA8 十大新特性详解
- css sprites