习题 3-8 循环小数(Repeating Decimals, ACM/ICPC World Finals 1990, UVa202)

习题 3-8 循环小数(Repeating Decimals, ACM/ICPC World Finals 1990, UVa202)

题目描述:
输入整数a和b (0<=a<=3000, 1<=b<=3000),输出a/b的循环小数表示以及循环节长度。例如a=5, b=43,小数表示为0.(116279069767441860465),循环节长度为21

在这里插入图片描述
在这里插入图片描述
第一想法就是字符串匹配,虽然走了弯路,好在最后AC了

#include<stdio.h>
#include<ctype.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

const int MAX_N = 10000;
int a, b;
int resInt;    // 存储结果的整数部分 
char res[MAX_N];  // 存储结果的小数部分 
char cycle[2*MAX_N]; // 存储循环节 

int main(){
   
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	while(scanf("%d%d", &a, &b) == 2) {
     // 当成功读取到a和b 
	
		memset(res, '0', sizeof(res));  // 重置结果和循环节 
		memset(cycle, '\0', sizeof(cycle));
		
		
		// 计算整数部分 
		int numA = a, numB = b;
		resInt = a/b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值