循环小数
作者:互联网
poj1930
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const ll MAXN=45000;
const int MOD=10000000;
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b,a%b);
}
int main(){
char str[100];
int num,k,all,a,b,i,j,mina,minb,l;
while(cin>>str&&strcmp(str,"0")){
mina=minb=1000000000;
for(i=2,all=0,l=0;str[i]!='.';i++){
all=all*10+str[i]-48;
l++;
}
for(num=all,k=1,i=1;i<=l;i++){
num/=10;
k*=10;
a=all-num;
b=(int)pow(10.0,l-i)*(k-1);
j=gcd(a,b);
if(b/j<minb){
mina=a/j; minb=b/j;
}
}
cout<<mina<<'/'<<minb<<endl;
}
return 0;
}
Chemin Du Retour
发布了2 篇原创文章 · 获赞 1 · 访问量 30
私信
关注
标签:循环小数,int,mina,ll,str,include,minb 来源: https://blog.csdn.net/weixin_45535964/article/details/104522594