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> # ...
随机推荐
- Extjs 6 MVC开发模式(一)
1.Extjs就绪函数 1)导入Extjs的CSS <link rel="stylesheet" type="text/css" href="r ...
- latex 固定图片位置
1,插入并列的子图 \usepackage{subfigure} \begin{figure}[H] \centering \subfigure[SubfigureCaption]{ \label{F ...
- Jq超链接提示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 结构体 + typedef
简单结构体 struct student{ char name[20]; //可以用scanf或者直接赋值 *如果用char *name 在用scanf时没有内存接收 long id; int ...
- ThinkPHP框架搭建及常见问题(Apache或MySQL无法启动)----简单的初体验
有一定基础的人勿进,这篇讲的只是零基础入门,都是我刚接触以及我所了解到的人刚开始有疑惑的地方,具体框架介绍会在后面的博客中介绍 这一篇只是为了一个简单的页面显示而介绍的方法,不涉及代码,开发环境,所以 ...
- C++ primer学习记录(个人猜想未测试版本)
学习版本:第五版. 本博文主要记录个人曾经并不知晓知识细节. 因为linux下的编译环境还未进行学习.所以实际代码测试将在今后完成. 红色:需确认. 蓝色:重点. 1)const对象设定为仅在文件内有 ...
- shopnc 商家中心添加打印商品二维码功能
需求中提到需要增加每一件商品可以打印,用于线下体验店实体商品的二维码标签,客人可以根据手机扫二维码功能进行购买 任务描述: 1.如附件实现”批量打印标签“和单个商品”打印“标签功能. 2.标签有两种” ...
- 多线程 NSThread GCD
ios多线程实现种类 NSThread NSOperationQueue NSObject GCD *************** 1.NSThread //线程 第一种 NSThread *thre ...
- 如何:对 Web 窗体使用路由
配置用于路由的 ASP.NET 网站项目 1. 在应用程序的 Web.config 文件中,将 ASP.NET 路由程序集添加到 assemblies 元素,如下面的示例所示: <add ass ...
- mysql 匹配update
update 语句示例: UPDATE `zjzc`.`QRTZ_SCHEDuler_state` SET `ip`='220.191.34.246' WHERE `sn`='3117764' and ...