其他分享
首页 > 其他分享> > 1069 The Black Hole of Numbers (20 分)

1069 The Black Hole of Numbers (20 分)

作者:互联网

注意不满\(4\)位的话要补成\(4\)位。

string s;
set<int> S;

int main()
{
    cin>>s;
    while(s.size()<4) s='0'+s;

    while(true)
    {
        sort(s.begin(),s.end(),greater<char>());
        string sa=s;

        reverse(s.begin(),s.end());
        string sb=s;

        int a=stoi(sa),b=stoi(sb);
        int res=a-b;

        if(S.count(res)) break;
        else
        {
            printf("%04d - %04d = %04d\n",a,b,res);
            S.insert(res);
            s=to_string(res);
            while(s.size()<4) s='0'+s;
        }
    }
    //system("pause");
    return 0;
}

标签:1069,20,string,int,res,04d,stoi,Hole,size
来源: https://www.cnblogs.com/fxh0707/p/14397724.html