求1/n(是循环小数只输出第一个循环节)
思路:模拟求余
http://acm.nyist.net/JudgeOnline/problem.php?pid=330
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int vis[100005];
int main()
{
int d,n;
cin>>d;
while(d--)
{
cin>>n;
if(n==1)
printf("1\n");
if(n<0)
{
printf("-0.");
n=-n;
}
else
cout<<"0.";
memset(vis,0,sizeof(vis));
int t=1;
while(!vis[t]&&t!=0)
{
vis[t]=1;
t*=10;
printf("%d",t/n);
t%=n;
}
cout<<endl;
}
}