蒟蒻66分求助
查看原帖
蒟蒻66分求助
182229
songyuan888楼主2021/2/8 14:02
#include<iostream>
using namespace std;
struct node
{
    int b;
    int c;
}a[100010];
int main()
{
    int n,m,t,i,j;
    bool d,f;
    cin>>n>>m;
    if(n%m==0)
    {
    	cout<<n/m<<".0"<<endl;//αβγθ 
    	return 0;
	}
    cout<<n/m<<".";
    n=n%m;
    t=0;
    a[1].c=n;
    for(i=1;;i++)
    {
        a[i].b=n*10/m;
        a[i+1].c=n*10%m;
        n=n*10%m; 
        if(n==0)
        {
        	for(j=1;j<=i;j++)
        		cout<<a[j].b;
        	cout<<endl;
        	break;
		}
		d=0;
        for(j=1;j<=i-1;j++)
        {
            if(n==a[j].c)
            {
                d=1;
                t=j;
                break;
            }
        }
        if(d==1)
        {
        	for(j=1;j<=t-1;j++)
        		cout<<a[j].b;
			cout<<"(";
            for(j=t;j<=i;j++)
                cout<<a[j].b;
            cout<<")"<<endl;
            break;
        }
    }
    return 0;
}
//45 56
2021/2/8 14:02
加载中...