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 ;}