Răspuns:
#include <iostream>
using namespace std;
int n,m,cod,v[6], t, k,i,j;
int main()
{
cin >> n;
m=n;
while (m)
{
v[++k]=m%10;
m/=10;
}
cod=n;
for (i=1; i<=k/2; i++)
{
t=v[i]; v[i]=v[k+1-i]; v[k+1-i]=t;
}
for (i=1; i<=k; i++) cout << v[i] << " ";
cout << "\n";
int z;
for (i=1; i<k; i++)
{
t=v[k]; m=0; z=1;
for ( j=k; j>1; j--)
{
v[j]=v[j-1];
m=m+v[j]*z;
z*=10;
}
v[1]=t;
m=m+v[1]*z;
if (m<cod) cod=m;
}
cout << cod;
}
Explicație: