nyoj 一个简单的数学题

http://acm.nyist.net/JudgeOnline/problem.php?pid=330

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 int vis[1000005];
 4 int main()
 5 {
 6     int t;
 7     int n;
 8     scanf("%d",&t);
 9     while(t--)
10     {
11         memset(vis,0,sizeof(vis));
12         scanf("%d",&n);
13         if(n==1)
14         {
15             printf("1\n");
16             continue;
17         }
18         if(n==-1)
19         {
20             printf("-1\n");
21             continue;
22         }
23         if(n<0)
24         {
25             printf("-0.");
26             n=-n;
27         }
28         else printf("0.");
29         int tt=1;
30         while(tt)
31         {
32             tt=tt*10;
33             if(vis[tt]) break;
34             vis[tt]=1;
35             printf("%d",tt/n);
36             tt=tt%n;
37             
38         }
39         printf("\n");
40         
41     }
42 }

 

posted on 2012-08-25 11:12  仁者无敌8勇者无惧  阅读(111)  评论(0编辑  收藏  举报

导航