# Fractions to Decimals_usaco2.4.5_暴力

## 題目描述 Description

1/3 = .33333333 寫成 0.(3)
41/333 = 0.123123123… 寫成 0.(123)

1/3 = 0.(3)
22/5 = 4.4
1/7 = 0.(142857)
2/2 = 1.0
3/8 = 0.375
45/56 = 0.803(571428)

## 程式 Code

``````/*
ID:wjp13241
PROG:fracdec
LANG:C
*/
#include <stdio.h>
#include <queue>
using namespace std;
struct frac
{
int mr,dr;
};
queue<frac>q;
int t[100001];
int main()
{
freopen("fracdec.in","r",stdin);
freopen("fracdec.out","w",stdout);
int a,b,st,ed,v=1,cnt=0;
scanf("%d%d",&a,&b);
printf("%d.",a/b);
q.push((frac){a,b});
while (q.size())
{
frac now=q.front();q.pop();
int tmp=now.mr%now.dr;
if (!t[tmp])
{
q.push((frac){tmp*10,now.dr});
t[tmp]=  cnt;
}
else
{
st=t[tmp];
ed=cnt-st;
break;
}
}
int tmp=a/b;
do{v  ;}while (tmp/=10);
a%=b;
if (!a)
printf("0");
while (--st)
{
printf("%d",a*10/b);
a=a*10%b;
v%=76;
if (!v)
printf("\n");
}
if (a)
{
printf("(");
v%=76;
if (!v)
printf("\n");
while (ed--)
{
printf("%d",a*10/b);
a=a*10%b;
v%=76;
if (!v)
printf("\n");
}
printf("%d)",a*10/b);
}
printf("\n");
return 0;
}``````