代码实现
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
do
{
s.insert(s.begin(), 4 - s.size(), '0'); // 不够四位,在前面补0
string t = s;
sort(t.begin(), t.end());
sort(s.begin(), s.end(), greater<char>());
printf("%04d - %04d = %04d\n", stoi(s), stoi(t), stoi(s) - stoi(t));
s = to_string(stoi(s) - stoi(t));
} while (s != "0" && s != "6174");
return 0;
}