[Cpp]
/*************************************** **************************\
For example,
Input:
3
1 2 3
Output:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
\*************************************** **************************/
# Include <stdio. h>
# Include <string. h>
# Include <assert. h>
Const int maxn = 100;
Int num [maxn];
Bool used [maxn];
Int ans [maxn];
Void output (int n)
{
For (int I = 0; I <n; I ++)
{
If (I <n-1)
Printf ("% d", ans [I]);
Else
Printf ("% d \ n", ans [I]);
}
}
Void fullPerm (int n, int dep)
{
If (dep> = n)
{
Output (dep );
Return;
}
For (int I = 0; I <n; I ++)
{
If (! Used [I])
{
Used [I] = true;
Ans [dep] = num [I];
FullPerm (n, dep + 1 );
Used [I] = false;
}
}
}
Void test ()
{
Int n = 0;
While (scanf ("% d", & n )! = EOF)
{
If (n = 0) break;
For (int I = 0; I <n; I ++)
Scanf ("% d", & num [I]);
Memset (used, false, sizeof (used ));
Memset (ans,-1, sizeof (ans ));
FullPerm (n, 0 );
}
}
Int main ()
{
Test ();
Return 0;
}
/*************************************** **************************\
For example,
Input:
3
1 2 3
Output:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
\*************************************** **************************/
# Include <stdio. h>
# Include <string. h>
# Include <assert. h>
Const int maxn = 100;
Int num [maxn];
Bool used [maxn];
Int ans [maxn];
Void output (int n)
{
For (int I = 0; I <n; I ++)
{
If (I <n-1)
Printf ("% d", ans [I]);
Else
Printf ("% d \ n", ans [I]);
}
}
Void fullPerm (int n, int dep)
{
If (dep> = n)
{
Output (dep );
Return;
}
For (int I = 0; I <n; I ++)
{
If (! Used [I])
{
Used [I] = true;
Ans [dep] = num [I];
FullPerm (n, dep + 1 );
Used [I] = false;
}
}
}
Void test ()
{
Int n = 0;
While (scanf ("% d", & n )! = EOF)
{
If (n = 0) break;
For (int I = 0; I <n; I ++)
Scanf ("% d", & num [I]);
Memset (used, false, sizeof (used ));
Memset (ans,-1, sizeof (ans ));
FullPerm (n, 0 );
}
}
Int main ()
{
Test ();
Return 0;
}