【习题 3-8 UVA - 202】Repeating Decimals
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
余数出现循环节。
就代表出现了循环小数。
【代码】
#include <bits/stdc++.h>
using namespace std;
int a,b;
int bo[4000];
vector <int> v;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
freopen("rush_out.txt","w",stdout);
#endif
int kase = 0;
while (~scanf("%d%d",&a,&b)){
kase++;
memset(bo,0,sizeof bo);
v.clear();
printf("%d/%d = ",a,b);
printf("%d.",a/b);
int cnt = 0;
if (a%b==0){
cnt = 1;
printf("(0)");
}else{
int x = a%b;
v.push_back(x*10/b);
bo[x] = 1;
int now = 1;
x = x*10%b;
while (1){
if (bo[x]){
cnt = now-bo[x]+1;
int j = 0;
for (int i = 0;i < bo[x]-1;i++) {
j++;
if (j>50) break;
putchar(v[i]+'0');
}
putchar('(');
for (int i = bo[x]-1;i < (int) v.size();i++) {
j++;
if (j > 50){
printf("...");
break;
}
putchar(v[i]+'0');
}
putchar(')');
break;
}
now++;
bo[x] = now;
v.push_back(x*10/b);
x = x*10%b;
}
}
puts("");
printf(" %d = number of digits in repeating cycle",cnt);
puts("");
puts("");
}
return 0;
}
【习题 3-8 UVA - 202】Repeating Decimals的更多相关文章
- UVa 202 Repeating Decimals(抽屉原理)
Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...
- UVa 202 - Repeating Decimals
给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来 模拟除法运算 把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间. 要注意50个数之后要省略号...每一次输出之后多打一个回车 ...
- uva 202(Repeating Decimals UVA - 202)
题目大意 计算循环小数的位数,并且按照格式输出 怎么做 一句话攻略算法核心在于a=a%b*10,用第一个数组记录被除数然后用第二个数组来记录a/b的位数.然后用第三个数组记录每一个被除数出现的位置好去 ...
- UVa 202 Repeating Decimals【模拟】
题意:输入整数a和b,输出a/b的循环小数以及循环节的长度 学习的这一篇 http://blog.csdn.net/mobius_strip/article/details/39870555 因为n% ...
- UVa 202 Repeating Decimals 题解
The decimal expansion of the fraction 1/33 is 0.03, where the 03 is used to indicate that the cycle ...
- Repeating Decimals UVA - 202
The / repeats indefinitely with no intervening digits. In fact, the decimal expansion of every ratio ...
- Repeating Decimals UVA - 202---求循环部分
原题链接:https://vjudge.net/problem/UVA-202 题意:求一个数除以一个数商,如果有重复的数字(循环小数),输出,如果没有,输出前50位. 题解:这个题一开始考虑的是一个 ...
- UVa202 Repeating Decimals
#include <stdio.h>#include <map>using namespace std; int main(){ int a, b, c, q, r, p ...
- uva 202
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> # ...
随机推荐
- Unityclient通信測试问题处理(一)
Unityclient通信測试问题处理(一) 近期在測试程序的通信模块时.遇到了一个问题:Unity的API函数仅仅能在主线程中调用.而作为client程序,我单独启用了一个监听线程来接收服务端发送的 ...
- 基于SVM的数据分类预測——意大利葡萄酒种类识别
update:把程序源代码和数据集也附上http://download.csdn.net/detail/zjccoder/8832699 2015.6.24 --------------------- ...
- tensorflow 语法及 api 使用细节
1. tf.nn.conv2d 的参数 padding='SAME' ⇒ 卷积之前的大小和卷积之后的大小一致,默认使用全 0 填充: padding='VALID' ⇒ 也即仅适用其有效部分,而不使用 ...
- 针对CDP协议攻击分析及安全防护
针对CDP协议攻击分析及安全防护 熟悉Cisco的朋友都知道CDP协议是思科公司独特的发现协议,在思科公司出产的所有路由器和交换机里面都能运行此协议,一台运行C D P的路由器或交换机能够得知与它直接 ...
- golang binarySearch
func binarySearch(nodes []*node, word Text) (int, bool) { start := end := len(nodes) - // 特例: { // 当 ...
- useradd---创建的新的系统用户
useradd命令 useradd命令用于Linux中创建的新的系统用户.useradd可用来建立用户帐号.帐号建好之后,再用passwd设定帐号的密码.而可用userdel删除帐号.使用user ...
- Resource Access Based on Multiple Credentials
A collection of multiple user credentials each associated with one of multiple different users is ob ...
- 谈谈Spine动画在产品中的应用
笔者介绍:姜雪伟,IT公司技术合伙人.IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,国家专利发明人;已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D ...
- 源代码看CoordinatorLayout.Behavior原理
在上一篇博客CoordinatorLayout高级使用方法-自己定义Behavior中,我们介绍了怎样去自己定义一个CoordinatorLayout的Behavior.通过文章也能够看出Behavi ...
- 搜索 debian8.7.1 ,google vs baidu
国外的 Linux 比国内流行, debian官方网站只能找到当前版本DVD文件.想找旧版的Debian在百度一圈后徒劳无功,于是把目标转向 google ,只需要输入 debian?8.7.1-i3 ...