UVA 202 repeating decimals

Source: Internet
Author: User

Test instructions: input integers A and B, (0<=a,b<=3000), output A/b cycle representation and the length of the loop section, output details see the original question

Analysis: If each time the division is simulated, the divisor once appeared. Since the maximum number is 3000, an array is opened to save the order in which each dividend appears.

1#include <iostream>2#include <map>3#include <queue>4#include <cstdio>5#include <cstring>6 using namespacestd;7 8 intvis[3005];9 Ten intMain () { One     intb; A      while(cin>>a>>b) { -memset (Vis,0,sizeof(Vis)); -         intnum=1; thequeue<int>Q; -         intn=a%b; -Q.push (A/b); -          while(!Vis[n]) { +vis[n]=num++; -n*=Ten; +Q.push (n/b); An%=b; at         } -printf"%d/%d =%d.", A,b,q.front ()); Q.pop (); -         inttt=1; -          while(!Q.empty ()) { -             if(tt==vis[n]&&tt<= -) -printf"("); in             if(tt> -){ -cout<<"..."; to                  Break; +             } -tt++; thecout<<Q.front (); Q.pop (); *         } $cout<<") \ n";Panax Notoginsengprintf"%d = number of digits in repeating cycle\n\n", num-vis[n]); -     } the     return 0; +}
View Code

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.