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;
}
来源:CSDN
作者:Chemin Du Retour
链接:https://blog.csdn.net/weixin_45535964/article/details/104522594