真是个讨厌的题目,输出及其猥琐。其他的点评,没了。
#include<iostream>
#include<cmath>
using namespace std;
const int maxn=100020;

int v[maxn];
int order[maxn];
int ans[maxn];//存放结果

int solve(int n,int m,int &pos)


{
memset(order,0,sizeof(order));
memset(v,0,sizeof(v));
int f=0;
int cnt=0;
v[n]=1;n*=10;
while(n)

{
if(v[n%m]==1)

{
f=1;ans[++cnt]=n/m;n%=m;
break;
}
else v[n%m]=1;
ans[++cnt]=n/m;
n%=m;
order[n]=cnt;
n*=10;
}
if(f==0)
pos=-1;
else pos=order[n];
return cnt;
}

int get(int n)


{
return log((double)n);
}

int main()


{

int n,m;
while(scanf("%d%d",&n,&m)!=EOF)

{
int cnt;
int pos;
if(n%m==0)

{
printf("%d.0\n",n/m);
continue;
}
int zhengshu=n/m;
n%=m;
int len=solve(n,m,pos);
if(zhengshu!=0)
cnt=get(zhengshu)+1;
else
cnt=2;
if(pos==-1)

{
printf("%d.",zhengshu);
for(int i=1;i<=len;i++)

{
printf("%d",ans[i]);
cnt++;
if(cnt%76==0)
printf("\n");
}
if(cnt%76!=0)
printf("\n");

}
else

{
printf("%d.",zhengshu);
for(int i=1;i<=pos;i++)

{
printf("%d",ans[i]);
cnt++;
if(cnt%76==0)
printf("\n");

}
printf("(");
cnt++;
if(cnt%76==0)
printf("\n");
for(int i=pos+1;i<=len;i++)

{
printf("%d",ans[i]);
cnt++;
if(cnt%76==0)
printf("\n");
}
printf(")");
cnt++;
if(cnt%76==0)
printf("\n");
if(cnt%76!=0)
printf("\n");
}
}
return 0;
}