没有说一定是4为数字
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
string step(string st)
{
sort(st.begin(),st.end());
string ss(st.size(),0);
using RI=reverse_iterator<string::iterator>;
copy(st.begin(),st.end(),RI(ss.end()));
string re=to_string(stoi(ss)-stoi(st));
re=string(4-re.size(),'0')+re;
cout<<ss<<" - "<<st<<" = "<<re<<endl;
return re;
}
int main()
{
string st;
cin>>st;
st=string(4-st.size(),'0')+st;
if(all_of( st.begin(), st.end(), [&] (char t) {return t==st[0]; } ))
cout<<st<<" - "<<st<<" = 0000\n";
else while((st=step(st))!="6174");
return 0;
}