标签:style blog http color io os ar sp div
/*
题目大意:求解1/n;
解题思路:写一个输出小数的算法
关键点:如何处理小数点循环输出
解题人:lingnichong
解题时间:2014-10-18 09:04:22
解题体会:输出小数的算法还没完全理解,先记着
*/
#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)//分情况,当n为1时,直接算
printf("%d\n",1/n);
else
{
memset(a,0,sizeof(a));//考虑n为0的情况
if(n<0)
{
n=-n;
printf("-0.");
}
else
printf("0.");
t=1;
while(a[t]!=1&&t!=0)//输出小数
{
a[t]=1;
t*=10;
printf("%d",t/n);
t%=n;
}
printf("\n");
}
}
return 0;
}
标签:style blog http color io os ar sp div
原文地址:http://blog.csdn.net/qq_16767427/article/details/40207983