1019

#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>


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 <<setw(4)<< max_tmp << " - " << setw(4)<< min_tmp <<" = "<< setw(4)<< r<<endl;
            n = r;
            max_tmp = str_to_max(n);
            min_tmp = str_to_min(n);
            r = max_tmp - min_tmp;
            if (r==0)
            {
                cout << setw(4) << max_tmp << " - " << setw(4) << min_tmp << " = " << "0000" ;
                return 0;
            }
        }
        cout << setw(4)<< max_tmp << " - " << setw(4)<< min_tmp << " = " << setw(4)<< r;
    }


    cout << endl;
    system("pause");
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • day 59 第二章 Mr Willy Wonka's Factory In the evenings,after...
    123逍遙游閱讀 666評(píng)論 0 0
  • 每個(gè)行業(yè),都有一個(gè)別人不知道的崗位存在著。比如說(shuō)廣告編排。 說(shuō)白了,就是一個(gè)頻道24小時(shí)播出的所有廣告的編輯排序,...
    戎馬未央閱讀 541評(píng)論 0 0
  • 感賞昨日兒子1點(diǎn)多才睡,今天堅(jiān)持按正常時(shí)間起床,晨讀,打卡。 體訓(xùn)老師周末要出差,問(wèn)是否能改為今天,我短信問(wèn)兒子,...
    玲03閱讀 288評(píng)論 0 1
  • 今天做項(xiàng)目的時(shí)候,發(fā)現(xiàn)一個(gè)問(wèn)題,就是切換賬號(hào)A->B的以后發(fā)現(xiàn),還留有A賬號(hào)的數(shù)據(jù)(公司app數(shù)據(jù)都是跟賬號(hào)有關(guān),...
    墨狂之逸才閱讀 1,146評(píng)論 0 50
  • 最初的我們 絲毫沒(méi)有察覺(jué)時(shí)間。 轉(zhuǎn)眼, 卻到了各奔東西的時(shí)候了。 或許吧,我難過(guò)了 為什么不去珍惜。 有人說(shuō):大了...
    柒玖之間閱讀 192評(píng)論 1 1

友情鏈接更多精彩內(nèi)容