uva 275 Expanding Fractions
来源:互联网 发布:学directx编程要多久 编辑:程序博客网 时间:2024/05/21 09:04
题目:给你一个分数的分子和分母,求出他的循环节。
Sample Input
3 7
345 800
112 990
53 122
0 0
Sample Output
.428571The last 6 digits repeat forever.
.43125This expansion terminates.
.113The last 2 digits repeat forever.
.4344262295081967213114754098360655737704918032786885245901639The last 60 digits repeat forever.
#include<cstdio>
#include<cstring>
#include<stack>
#include<iostream>
using namespace std;
#define M 3000
int main()
{
int a,b;
a = b = 0;
while((cin >> a >> b)&& a+b){
printf(".");
int yushu[M] = {0},shang[M] = {0};
/// memset(shang, 0, 30);
a %= b;
a *= 10;
for(int t = 0; t < M; t++) {
shang[t] = a/b;
a = a%b;
yushu[t] = a;
a *= 10;
}
int i ,j;
for(i = 0; i < M; i++){
for(j = i + 1; j < M; j++) {
if(((shang[j] == shang[i]) && (yushu[j] == yushu[i]) )|| (i >= 100)){
goto a1;
}
}
}
a1:
if((shang[j] == 0) && ((j-i)==1)){
for(int m = 0; m < j-1; m++){
if(m % 50 == 49) printf("\n");
printf("%d",shang[m]);
}
printf("\nThis expansion terminates.\n\n");
}
else{
for(int m = 0; m < j; m++){
if(m % 50 == 49) printf("\n");
printf("%d",shang[m]);
}
printf("\n");
printf("The last %d digits repeat forever.\n\n",j-i);
}
}
return 0;
}
- UVa 275 - Expanding Fractions
- uva 275 Expanding Fractions
- ACM--Expanding Fractions
- POJ 1140 Expanding Fractions 笔记
- ACM pku 1140 解题报告(Expanding Fractions )
- 基础题 HOJ 1140 Expanding Fractions
- poj 1140 Expanding Fractions 除法模拟
- UVa 10668 - Expanding Rods
- UVa 10814 - Simplifying Fractions
- UVA 10976 - Fractions Again?!
- UVA 10976 - Fractions Again?!
- uva 834 - Continued Fractions
- UVa 834 - Continued Fractions
- UVA-10976 - Fractions Again?!
- UVA - 10976 Fractions Again?!
- UVa 10976 - Fractions Again?!
- UVa 10976 - Fractions Again?!
- UVa 10976 - Fractions Again?!
- ZigBee 用IO口模拟I2C驱动程序
- nginx 中的 rewrite 和 try_files
- MyEclipse配置Tomcat7
- django入门笔记
- 图解插入排序--直接插入排序
- uva 275 Expanding Fractions
- 移动端如何让页面强制横屏
- struts2.3.23升级到struts2.3.32
- git基本操作
- linux下的管道
- MyEclipse10.6 myeclipse2013下添加jadClipse反编译插件 .用于显示源码
- 如何用npm来安装jsx插件和安装fis插件
- Spring的BeanFactoryPostProcessor和BeanPostProcessor
- 华为oj初级 字符串通配符