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

【题意】

在这里输入题意

【题解】

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

【代码】

#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. JAVA基础针对自己薄弱环节总结02(循环)

    循环 A:水仙花. classShuiXianHua { public static void main(String[] args) { for(int i=101;i<1000;i++) { ...

  2. Java:异常体系

    异常的类别:可处理异常,运行时异常,非运行时异常 子类重写父类方法,父类方法有异常抛出, 子类重写父类的方法? 不能比父类抛出更大的异常 前言:java 中的异常处理机制你真的理解了吗?掌握了吗?ca ...

  3. 小米开源文件管理器MiCodeFileExplorer-源码研究(7)-Favorite收藏管理和SQLite数据库CRUD

    FavoriteDatabaseHelper,存储favorite数据,到SQLite数据库.SQLiteOpenHelper是一个帮助管理数据库和版本的工具类.通过继承并重载方法,快速实现了我们自己 ...

  4. 【Uva 1289】Stacking Plates

    [Link]: [Description] 有n(1≤n≤50)堆盘子,第i堆盘子有hi个盘子(1≤hi≤50),从上到下直径不减.所有盘 子的直径均不超过10000.有如下两种操作. split:把 ...

  5. WPF转换器

    1. 前文 在普遍的也业务系统中, 数据要驱动到操作的用户界面, 它实际储存的方式和表达方式会多种多样, 数据库存储的数字 0或1, 在界面用户看到显示只是 成功或失败, 或者存储的字符.或更多的格式 ...

  6. .Net 开源控件 NPlot使用小结

    NPlot是一款非常难得的.Net平台下的图表控件,能做各种曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也非常符合程序员的习惯.授权方式为BSD许可证. 下载链接: http:/ ...

  7. CDN服务上线,DNSPOD布局云端生态圈

    爱因斯坦曾说过,我从不去想未来,由于它来得已经够快的了.是的,随着互联网的高速发展,我们的生活节奏越来越快,可是人们的耐心却像鞋底一样越磨越薄. 遥控器按一下,鼠标点一下,仅仅要认为没意思或者等待时间 ...

  8. nyist oj 1058 部分和问题 (DFS搜索)

    部分和问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 给定整数a1.a2........an.推断能否够从中选出若干数,使它们的和恰好为K. 输入 首先,n和k ...

  9. apache 使用 mod_fcgid.so模块时 配置指令

    FcgidBusyScanInterval指令 说明:扫描繁忙超时进程的间隔 语法: FcgidBusyScanInterval seconds 默认:FcgidBusyScanInterval 12 ...

  10. android抓取各种log的方法

    1.logcat (四类log buffer是main,radio.system.events) adb wait-for-device logcat adb logcat -v time > ...