Pagini recente » Cod sursa (job #545586) | Cod sursa (job #239389) | Cod sursa (job #694317) | Cod sursa (job #912801) | Cod sursa (job #857088)
Cod sursa(job #857088)
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int a[16];
int n;
void Back( int x );
bool ok( int x );
int main()
{
fin >> n;
Back( 1 );
fin.close();
fout.close();
return 0;
}
void Back( int x )
{
for( int i = 1; i <= n; ++i )
{
a[x] = i;
if( ok( x ) )
{
if( x == n )
{
for( int j = 1; j <= n; ++j )
fout << a[j] << ' ';
fout << '\n';
}
Back( x + 1 );
}
}
}
bool ok( int x )
{
for( int i = 1; i < x; ++i )
if( a[x] == a[i] )
return false;
return true;
}