#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;
}
1019
最后編輯于 :
?著作權(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ù)。
【社區(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)容
- 每個(gè)行業(yè),都有一個(gè)別人不知道的崗位存在著。比如說(shuō)廣告編排。 說(shuō)白了,就是一個(gè)頻道24小時(shí)播出的所有廣告的編輯排序,...
- 今天做項(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),...