http://acm.hdu.edu.cn/showproblem.php?pid=2522

1 #include<stdio.h> 2 #include<string.h> 3 int mark[100002]; 4 void pow(int x) 5 { 6 int t; 7 mark[1]=1; 8 t=1; 9 while(t) 10 { 11 t=t*10; 12 printf("%d",t/x); 13 t=t%x; 14 if(mark[t])//再次出现相同的余数,表示开始循环 15 break; 16 mark[t]=1;//将出现的余数标记 17 } 18 } 19 int main() 20 { 21 int t,n; 22 scanf("%d",&t); 23 while(t--) 24 { 25 scanf("%d",&n); 26 memset(mark,0,sizeof(mark)); 27 if(n<0) 28 { 29 printf("-"); 30 n=-n; 31 } 32 if(n==1) 33 { 34 printf("1\n"); 35 continue; 36 } 37 printf("0."); 38 pow(n); 39 printf("\n"); 40 } 41 return 0; 42 }