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);
}