【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

余数出现循环节。
就代表出现了循环小数。

【代码】

#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的更多相关文章

  1. UVa 202 Repeating Decimals(抽屉原理)

    Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...

  2. UVa 202 - Repeating Decimals

    给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来 模拟除法运算 把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间. 要注意50个数之后要省略号...每一次输出之后多打一个回车 ...

  3. uva 202(Repeating Decimals UVA - 202)

    题目大意 计算循环小数的位数,并且按照格式输出 怎么做 一句话攻略算法核心在于a=a%b*10,用第一个数组记录被除数然后用第二个数组来记录a/b的位数.然后用第三个数组记录每一个被除数出现的位置好去 ...

  4. UVa 202 Repeating Decimals【模拟】

    题意:输入整数a和b,输出a/b的循环小数以及循环节的长度 学习的这一篇 http://blog.csdn.net/mobius_strip/article/details/39870555 因为n% ...

  5. 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 ...

  6. Repeating Decimals UVA - 202

    The / repeats indefinitely with no intervening digits. In fact, the decimal expansion of every ratio ...

  7. Repeating Decimals UVA - 202---求循环部分

    原题链接:https://vjudge.net/problem/UVA-202 题意:求一个数除以一个数商,如果有重复的数字(循环小数),输出,如果没有,输出前50位. 题解:这个题一开始考虑的是一个 ...

  8. UVa202 Repeating Decimals

    #include <stdio.h>#include <map>using namespace std; int main(){    int a, b, c, q, r, p ...

  9. uva 202

    #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> # ...

随机推荐

  1. 整合struts2+spring+hibernate

     一.准备struts2+spring+hibernate所须要的jar包:        新建web项目并将jar包引入到project项目中. 二.搭建struts2环境        a.在 ...

  2. awk依照多个分隔符进行切割

    我们知道awk能够进行类似于cut之类的操作.如一个文件data例如以下 zhc-123|zhang hongchangfirst-99|zhang hongchang-100|zhang 假设我们 ...

  3. .Net MVC小尝试

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  4. vue中关于prop

    组件之间的项目通信在vue中十分常见,父组件的数据传到子组件需要prop的支持,我们来看下prop 1.html的特性名大小写不敏感,浏览器会把所有大写字母解释为小写字母,使用dom模板时,使用等价的 ...

  5. 类数组对象arguments 和 数组对象

    arguments并不是一个真正的数组,而是一个“类似数组(array-like)”的对象: 就像下面的这段输出,就是典型的类数组对象: {0:12, 1:23} 一.类数组 VS 数组 相同点: 都 ...

  6. 3.cocos代码入口

    模拟代码进入过程: main.cpp #include <iostream> #include "AppDelegate.h" #include "CCApp ...

  7. c# for 和 foreach

    1给定长度 不需要计算长度的 for比foreach循环效率高 2 在不确定长度 或者计算长度有性能损耗的时候 用foreach比较方便 2336 循环语句是编程的基本语句,在C#中除了沿用C语言的循 ...

  8. 003 python 注释/数据类型/运算符/输入输出/格式化输出

    集成开发环境 pycharm 工欲善其事,必先利其器 pycharm是具备一般的python ide的功能,同时呢支持调试,语法高亮,代码管理,智能提示 加快快发的速度,提高开发效率 注释 what ...

  9. 今日SGU 5.9

    SGU 297 题意:就是求余数 收获:无 #include<bits/stdc++.h> #define de(x) cout<<#x<<"=" ...

  10. 03010_防止SQL注入

    1.预处理对象 (1)使用PreparedStatement预处理对象时,建议每条sql语句所有的实际参数,都使用逗号分隔: String sql = "insert into sort(s ...