Uva 202.Repeating Decimals

Source: Internet
Author: User

The main idea is to take repeating decimal's circulation section

More clear thinking

Completely simulates the division of the human brain, while grouping marks dividend and divisor, judging the cyclic section

The middle of the need to judge is to divide and not to do two things

Finally, pay attention to the format, each two output to have a blank line, and the second line has 3 spaces before

A bit of code

1#include <cstdio>2#include <cstring>3 using namespacestd;4 5 #defineREP (n) for (int o=0;o<n;o++)6 7 structnode{8     intb;9 };Ten  One BOOLDo (); A intVisited (intAintB,node n[],intlen); - intMain () { -     //freopen ("In.txt", "R", stdin); the      while(Do ()); -     return 0; - } -  + BOOLDo () { -     intb; +Node mark[10000]; A     intCnt=1; at     int decimal[10000]; -  -     if(SCANF ("%d%d", &a,&b) ==eof)return false; -REP (10000) mark[o]={0, b}; -REP (10000)decimal[o]=-1; -      in     intx= (a%b) *Ten; -      while(1){ to         //printf ("%d/%d =%d ...%d mark[%d]={%d,%d}\n", x,b,x/b,x%b,cnt,x,b); +         decimal[cnt]=x/b; -         if(Visited (x,b,mark,cnt)) Break; themark[cnt]={x,b}; *x= (x%b) *Ten; $cnt++;Panax Notoginseng     } -cnt--; the     //REP (cnt+1) printf ("mark[%d]={%d,%d}\n", o,mark[o].a,mark[o].b); +     intBegin=visited ((mark[cnt].a%b) *Ten, mark[cnt].b,mark,cnt); A  the     //printf ("\n\n%d\n\n", begin); +printf"%d/%d =%d.", a,b,a/b); -      for(intI=1; i<=cnt;i++){ $         if(begin==i) printf ("("); $printf"%d",decimal[i]); -         if(i== -){ -printf"..."); the              Break; -         }Wuyi     } the     if(begin==0) printf ("(0"); -printf") \ n%d = number of digits in repeating cycle\n\n", begin==0?1: cnt-begin+1); Wu     return true; - } About  $ intVisited (intAintB,node n[],intLen) { -      for(into=1; o<=len;o++){ -         if(n[o].a==a&&n[o].b==b) { -             returno; A         } +     } the     return 0; -}

Uva 202.Repeating 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.