#include <stdio.h>
#include<string.h>
int high(char y[],int z)
{
int x[10000];
for(int i=0;i<z;i++)
{
x[i]=y[i]-'0';
}
int a=0,p=0,q=0,b=0,r=1,l;
for(int i=0;i<z;i++)
{
for(int j=0;j<z;j++)
{
if(x[i]>x[j])
{
a=x[i];
x[i]=x[j];
x[j]=a;
}
}
}
for(int i=0;i<z;i++)
{
p+=x[i]*r;
r=r*10;
}
for(int i=0;i<z;i++)
{
for(int j=0;j<z;j++)
{
if(x[i]<x[j])
{
b=x[i];
x[i]=x[j];
x[j]=b;
}
}
}
r=1;
for(int i=0;i<z;i++)
{
q+=x[i]*r;
r=r*10;
}
l=q-p;
return l;
}
int main() {
char a[1000000],o[1000000];
int b[10000],c[10000],d[10000];
int x,y,z,t,i=1,p=1;
scanf("%s",a);
z=strlen(a);
for(int j=0;j<z;j++)
{
d[j]=a[j]-'0';
}
for(int j=z-1,k=1;j>=0;j--)
{
c[0]+=d[j]*k;
k=k*10;
}
while(p)
{
z=strlen(a);
c[i]=high(a,z);
sprintf(o,"%d",c[i]);
for(int j=0;j<z;j++)
{
a[j]=o[j];
}
for(int j=0;j<i;j++)
{
if(c[i]==c[j]) p=0;
}
i++;
}
printf("%d\n",i-1);
for(int j=0;j<i-1;j++)
{
printf("%d\n",c[j]);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: