L1-046 整除光棍 (20 分)

模拟除法的过程就好了,并不需要高精度了。

int main()
{
    int x;
    cin>>x;

    int r=0;
    int cnt=0;
    bool first=true;
    while(true)
    {
        r=r*10+1;
        cnt++;
        if(first && r/x)  // 第一个不为0的商作为最高位
        {
            first=false;
            cout<<r/x;
        }
        else if(!first)
            cout<<r/x;

        r%=x;
        if(r == 0) break;
    }
    cout<<' '<<cnt<<endl;
    //system("pause");
    return 0;
}
posted @ 2021-04-23 16:40  Dazzling!  阅读(34)  评论(0编辑  收藏  举报