UVa 202 - Repeating Decimals
给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来
模拟除法运算
把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间。
要注意50个数之后要省略号...
每一次输出之后多打一个回车...
#include <iostream>
#include <cstring>
using namespace std;
int a,b;
int flag[];//记录该被除数出现的位置
int ans[],num,cnt;
void fuc()
{
memset(flag,,sizeof(flag)); num=;
while(a>)
{
if(flag[a]>) break;
flag[a]=num;
ans[num]=a/b;
a%=b;
a*=; num++;
}
}
int main()
{
while(cin>>a>>b)
{
printf("%d/%d = ",a,b);
fuc();
printf("%d.",ans[]);//整数位 if(a>)
{
for(int i=;i<flag[a];i++) cout<<ans[i]; //循环体前
cout<<'(';
for(int i=flag[a];i<num&&i<=;i++)
{
cout<<ans[i];
}
if(num-flag[a]>=) cout<<"...";
cout<<')'<<endl;
printf(" %d = number of digits in repeating cycle\n\n",num-flag[a]);
}
else
{
for(int i=;i<num;i++) cout<<ans[i];
cout<<"(0)\n";
printf(" 1 = number of digits in repeating cycle\n\n");
} }
}
UVa 202 - Repeating Decimals的更多相关文章
- UVa 202 Repeating Decimals(抽屉原理)
Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...
- 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 ...
- 【习题 3-8 UVA - 202】Repeating Decimals
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 余数出现循环节. 就代表出现了循环小数. [代码] #include <bits/stdc++.h> using nam ...
- 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> # ...
随机推荐
- 沃通tomcat jks 安装配置
废话不多说上代码: <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtoc ...
- locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
安装好CentOS后,第一次进入系统使用locate命令,结果出现:locate: can not stat () `/var/lib/mlocate/mlocate.db': No such fil ...
- 198. House Robber,213. House Robber II
198. House Robber Total Accepted: 45873 Total Submissions: 142855 Difficulty: Easy You are a profess ...
- C++ 多态性浅谈
多态:一个接口, 多种方法.程序在运行时才决定调用的函数是什么. C++多态通过 虚函数实现, 虚函数允许子类重新定义成员函数, 子类override父类. 多态与非多态的实质区别:函数地址是早绑定还 ...
- setlocal enabledelayedexpansion
http://www.jb51.net/article/29323.htm 例1: 代码如下: @echo off set a=4 set a=5&echo %a% pause 结果:4 解 ...
- Font Awesome 4.0.3 字体图标完美兼容IE7
1.下载Font Awesome 4.0.3兼容包,http://www.thinkcmf.com/index.php?m=font 2.解压,并放到自己网站系统合适的位置(如果你的站已使用Font ...
- Azure File SMB3.0文件共享服务(3)
在Windows上使用Azure文件共享服务 之前简单介绍过,你可以通过SMB 3.0协议,将Azure文件共享挂载在本地,就如使用一个网络驱动器是一样的,但需要注意不同版本的Windows对于SMB ...
- Windows下Node.js开发环境搭建
1.http://nodejs.org/下载node.js运行环境安装 2.打开DOS命令行 .安装express框架 1 >npm install express 末尾显示如下为安装成功 .安 ...
- cf459A Pashmak and Garden
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
- uva 10041 Vito's Family_贪心
题意:给你n个房子的距离,问那个房子离别的房子的距离最近,并且输出与别的房子距离的总和 思路:排序一下,中间的房子离别房子距离必然是最少的. #include <iostream> #in ...