Usaco--2.4fractions to decimals

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.