#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
map<string,int> vis;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
while(cin>>n)
{
vis.clear();
string s(to_string(n));
int f=0;
while(vis[s]<=3)
{
vis[s]++;
sort(s.begin(),s.end(),greater<char>());
string mx=s;
sort(s.begin(),s.end(),less<char>());
string mn=s;
int a=0,b=0;
for(auto c:mx) a=a*10+c-'0';
for(auto c:mn) b=b*10+c-'0';
int cha=a-b;
string ans=to_string(cha);
s=ans;
}
map<string,int>::iterator iter;
stack<string> stk;
for(iter=vis.begin();iter!=vis.end();++iter) if(iter->second>=2) stk.push(iter->first);
while(!stk.empty()) cout<<stk.top()<<' ',stk.pop();
cout<<'\n';
}
return 0;
}
样例过了