USACO:Fractions to Decimals

/*
ID: Jang Lawrence
PROG: fracdec
LANG: C++
*/
#include
#include
#include
#include
#include
#include
#include
#define X first
#define Y second
#define sqr(a) ((a)*(a))
using namespace std;
typedef long long lng;
int x,y;
string an;
void f(int ini)
{
    if(ini>=10) f(ini/10);
    an+='0'+ini%10;
}
int  is[111111];
vector ans;
int main()
{
  #ifndef  DEBUG
  freopen("fracdec.in","r",stdin);
  freopen("fracdec.out","w",stdout);
  #endif
scanf("%d%d",&x,&y);
f(x/y);
x=x%y;
bool f=1;
while(!is[x])
{
   is[x]=ans.size()+1;
   ans.push_back((x*10)/y);
   x=(x*10)%y;
   if(x==0){is[x]=ans.size();f=0;break;}
}
an+='.';
for(int i=0;i

你可能感兴趣的:(usaco)