UVA-3.8-循环小数-202
#include <stdio.h>
#include <stdlib.h>
int main()
{
//freopen("D:\\output.txt", "w", stdout);
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
int num1[10100];
int num2[10100];
int m,n,i,j,k;
//int t=a/b;
//a=a%b;
//a=a*10;
int mark1=0,mark2=0;
int x1=a,y1=b;
for(i=1;;i++)
{
num1[i]=a/b;
num2[i]=a%b;
if(a%b==0)
{
mark1=1;
break;
}
if(i!=1)
{
for(j=1;j<i;j++)
{
if(num2[j]==num2[i])
{
mark2=1;
break;
}
}
if(mark2)
break;
}
a=(a%b)*10;
}
int x;
printf("%d/%d = ",x1,y1);
if(mark1)
{
if(i==1)
{
printf("%d.",num1[1]);
printf("(0)\n");
printf(" 1 = number of digits in repeating cycle\n");
}
else
{
for(x=1;x<=i;x++)
{
if(x==1)
printf("%d.",num1[x]);
else
printf("%d",num1[x]);
}
printf("(0)\n");
printf(" 1 = number of digits in repeating cycle\n");
}
}
if(mark2)
{
for(x=1;x<=j;x++)
{
if(x==1)
printf("%d.",num1[x]);
else
printf("%d",num1[x]);
}
printf("(");
{
if(i>51)
{
for(x=j+1;x<=51;x++)
printf("%d",num1[x]);
printf("...");
}
else
{
for(x=j+1;x<=i;x++)
printf("%d",num1[x]);
}
}
printf(")\n");
printf(" %d = number of digits in repeating cycle\n",i-j);
}
printf("\n");
}
return 0;
}