1019

#include
#include
#include
#include
#include


using namespace std;

inline int str_to_min(int a)
{
    string tmp = to_string(a);
    while (tmp.size() < 4)
    {
        tmp = tmp + "0";
    }

    sort(tmp.begin(), tmp.end());
    unsigned ret = stoi(tmp);
    return ret;
}
inline int str_to_max(int a)
{
    string tmp = to_string(a);
    while (tmp.size() <4)
    {
        tmp = tmp + "0";
    }

    sort(tmp.begin(), tmp.end(), [](char chr1, char chr2) {return chr1>chr2; });
    unsigned ret = stoi(tmp);
    return ret;
}

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

    int max_tmp = str_to_max(n);
    int min_tmp = str_to_min(n);
    int r = max_tmp -min_tmp ;
    if (r == 0)
    {
        cout << n << " - " << n << " = 0000";
    }
    else
    {
        cout.setf(ios::right);
        cout.fill('0');
        while (r!=6174)
        {
            cout <

你可能感兴趣的:(1019)