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

【题意】

在这里输入题意

【题解】

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

【代码】

#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. jni中调用java方法获取当前apk的签名文件md5值

    相应的java方法: void getsign(Context context) throws Exception { PackageInfo localPackageInfo = context.g ...

  2. php将数组或字符串写入文件

    //将数组保存在文件里 function export_to_file($file, $variable) { $fopen = fopen($file, 'wb'); if (!$fopen) { ...

  3. 轻松使用 Redis slowlog

    之前中秋项目搞活动,用户比较活跃 SE.Redis 频繁报 Timeout 异常,狂翻了一波 issues 发现提这个问题还蛮多的,作者非常频繁的提到使用 slowlog 这个命令进行排查,那么问题就 ...

  4. FFT之大数乘法

    #include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> ...

  5. PDF Adobe Acrobat 9 简体中文专业版(打印店内部的软件)(你懂的!)

    福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑         Java全栈大联盟   ...

  6. #学习笔记#——JavaScript 数组部分编程(三)

    3.在数组 arr 末尾添加元素 item.不要直接修改数组 arr,结果返回新的数组 主要考察数组的concat方法,代码如下: arr.concat(item); concat 方法不修改原数组. ...

  7. 搜寻Linux软件实用指南

    搜寻Linux软件实用指南  对于初学者来说,仅仅安装好Linux系统还是不够的,还需要安装大量的应用软件.许多下载网站都提供了诸如装机必备软件的下载,分门别类提供经典的工具软件下载.本文主要针对初学 ...

  8. JSP_Learn

    // 解决中文乱码的问题String name = new String((request.getParameter("name")).getBytes("ISO-885 ...

  9. 洛谷 P1177 【模板】快速排序(排序算法整理)

    P1177 [模板]快速排序 题目描述 利用快速排序算法将读入的N个数从小到大排序后输出. 快速排序是信息学竞赛的必备算法之一.对于快速排序不是很了解的同学可以自行上网查询相关资料,掌握后独立完成.( ...

  10. [Docker 官方文档] 理解 Docker

    http://segmentfault.com/a/1190000002609286 什么是 Docker? Docker 是一个用于开发.交付和执行应用的开放平台,Docker 设计用来更快的交付你 ...