Hdus 2522 A simple problem

Source: Internet
Author: User

Hdus 2522 A simple problem
A simple problemTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 3368 Accepted Submission (s): 1249


Problem DescriptionZty is obsessed with mathematical problems .. One day, yifenfei had a math problem and asked him to answer 1/n. But Zty cannot answer ^_^. Ask everyone to program and help him.

The integer T in the first line of Input, indicating the number of test groups. Followed by T rows, each row has an integer n (1 <=| n |<= 10 ^ 5 ).
Output 1/n. (It is a circular decimal number and only outputs the first circular section ).
Sample Input

4237168

Sample Output
0.50.30.1428570.005952380

Authoryifenfei
SourceHDU 2008-10 Programming Contest

Simulate Division operations.

Code on

# Include
 
  
# Include
  
   
Using namespace std; int main () {int a [100005], t; // an array is used to determine the number of digits in a loop. Scanf ("% d", & t); while (t --) {memset (a, 0, sizeof (a); int n; int flag = 0; scanf ("% d", & n); if (n = 1) {printf ("1 \ n"); // n is a continue ;} if (n <0) {n =-n; // if it is less than 0, first change to positive and flag = 1;} int l = 1; a [l] = 1; if (flag) printf ("-0. "); // output symbol else printf (" 0. "); while (l) // l is not 0 {l * = 10; // start the simulation, first multiply by 10 printf (" % d ", l/n); // output the first decimal place l % = n; // returns the remainder. Repeat the preceding operations if (a [l]) break; a [l] = l; // make a [l] = l. When the same loop occurs, a [l] directly jumps out. Ensure that there is only one circular section. } Printf ("\ n");} return 0 ;}
  
 


Related Article

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.