#include <iostream>
using namespace std;
void perm(char *s, int k, int n)
{
if(k==n)
{
for(int i=0; i<=n; i++)
cout<<s[i];
cout<<'\n';
}
else
{
char temp;
for(int i=k; i<=n; i++)
{
temp=s[i];
s[i]=s[k];
s[k]=temp;
perm(s, k+1, n);
temp=s[i];
s[i]=s[k];
s[k]=temp;
}
}
}
int main()
{
char s[4]={'1', '2', '3', '4'};
//char *s="1234 ";
perm(s, 0, 3);
return 0;
}