Nyoj 330 a simple mathematical problem]

Source: Internet
Author: User

/*
Solution 1/n;
Solution: Write an algorithm for outputting decimal places
Key point: how to process the decimal point loop output
Problem solving person: lingnichong
Solution time: 09:04:22
Problem-solving experience: the algorithm for outputting decimal places is not fully understood. Remember first
*/



A simple mathematical problem time limit: 3000 MS | memory limit: 65535 kb difficulty: 3
Description
ZYC recently fell in love with mathematics. One day, DJ came up with a math question to help him. Calculate 1/N, but ZYC cannot answer the question at one time. I hope everyone can help him with programming.
Input
The integer T in the first line indicates the number of test groups. Followed by T rows, each row has an integer N (1 <=| n |<= 10 ^ 5 ).
Output
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
Source
HDU
Uploaded
Pass this


# Include <stdio. h> # include <string. h> # define maxn 100000 + 10 char a [maxn]; int main () {int N, S, T; scanf ("% d", & S ); while (s --) {scanf ("% d", & N); If (n = 1 | n =-1) // the score, when N is 1, printf ("% d \ n", 1/n) is calculated directly; else {memset (A, 0, sizeof ()); // when n is 0, if (n <0) {n =-N; printf ("-0. ");} else printf (" 0. "); t = 1; while (A [T]! = 1 & T! = 0) // output decimal point {A [T] = 1; T * = 10; printf ("% d", T/N); T % = N ;} printf ("\ n") ;}} return 0 ;}




Nyoj 330 a simple mathematical problem]

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.