代码如下
#include<iostream>
#include<cstring>
#include<cstdio>
#define SIZE 50000
#define MAX 50
using namespace std;
int main()
{
intsurplus[SIZE],digit[SIZE],place[SIZE],t,te,tem,temp,a,b;
boolindex=false;
while(cin>>a>>b)
{
// if(cin.eof())
// return0;
//if(index)
//cout<<endl;
t=a/b;
te=a-t*b;
te*=10;
memset(surplus,0,sizeof(surplus));
tem=1;
surplus[te]=tem;
while(1)
{
if(te<b)
{
te*=10;
digit[tem]=0;
++tem;
}
else
{
digit[tem]=te/b;
te=te%b;
te*=10;
++tem;
}
if(surplus[te])
break;
surplus[te]=tem;
}
te=surplus[te];
printf("%d/%d = %d.",a,b,t);
temp=1;
while(temp<te)
{
cout<<digit[temp];
++temp;
}
cout<<'(';
if(tem-temp>49)
{
t=temp+50;
while(temp<t)
{
cout<<digit[temp];
++temp;
}
printf("...)n %d = number ofdigits in repeating cyclen",tem-te);
}
else
{
while(temp<tem)
{
cout<<digit[temp];
++temp;
}
printf(")n %d = number ofdigits in repeating cyclen",tem-te);
}
//index=true;
cout<<endl;
}
return0;
}
