其他分享
首页 > 其他分享> > 1069 The Black Hole of Numbers (20 分)【难度: 简单 / 知识点: 模拟】

1069 The Black Hole of Numbers (20 分)【难度: 简单 / 知识点: 模拟】

作者:互联网

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805400954585088

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    string a,b; cin>>a;
    int sum=stoi(a);
    do
    {
        a=to_string(sum);
        while(a.size()<4) a="0"+a;
        sort(a.begin(),a.end());
        b=a,reverse(b.begin(),b.end());
        sum=stoi(b)-stoi(a);
        printf("%s - %s = %04d\n",b.c_str(),a.c_str(),sum);
        if(sum==0) break;
    }while(sum!=6174);
}

标签:1069,知识点,20,string,do,int,sum,cn
来源: https://blog.csdn.net/qq_46527915/article/details/120918701