At the beginning of this topic, there is no idea, after all, double type to retain 16 decimal places. After looking at other people's ideas to find that we should simulate the process of fractional division, in the process of simulation if the remainder has already appeared in the previous, then it will be here to form a circular section; This topic is a bit more than the pit is the output format, I was on the top of the WA several rounds.
The code is as follows:
/*id:15674811Lang:c++prog:fracdec*/#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace Std;#define MAXN 110000intvis[maxn],ans[maxn],cnt;intMain () {Freopen ("Fracdec.in","R", stdin); Freopen ("Fracdec.out","W", stdout);//freopen("Lkl.txt","R", stdin);//freopen("A.txt","W", stdout);intNm; while(SCANF ("%d%d",&n,&m) {!=eof) {cnt=0;intD=1; memset (Vis,0, sizeof (VIS));printf("%d.", n/m);intt=n/m;if(t==0) d=2; while(t) {d++; T/=Ten; } n=n%m; vis[n]=1; while(true) {N=n*10;intt=n/m; N=n%m; ans[cnt++]=t;if(n==0) { for(intI=0; i<cnt;i++) {printf("%d", Ans[i]); d++;if(d%76==0)printf("\ n"); }printf("\ n"); Break; }if(Vis[n]) {intflag=0; for(intI=0; i<cnt;i++) {if(ans[i]==n*10/m&&!flag) {printf("("); d++; flag=1;if(d%76==0)printf("\ n"); }printf("%d", Ans[i]); d++;if(d%76==0)printf("\ n"); }printf(") \ n"); Break; } vis[n]=1; } }return 0;}
Usaco--2.4fractions to decimals