Pagini recente » Cod sursa (job #1856199) | Cod sursa (job #2415137) | Cod sursa (job #1526482) | Cod sursa (job #1936231) | Cod sursa (job #2029198)
#include <iostream>
#include <fstream>
using namespace std;
int x[30];
int n, m;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int cont(int nivel) {
for (int i=1;i<nivel; i++)
if (x[i] == x[nivel])
return 0;
return 1;
}
void back(int nivel) {
if (nivel > n) {
for (int i=1;i<=n;i++)
fout<<x[i]<<" ";
fout<<"\n";
} else {
for (int i=1;i<=n;i++) {
x[nivel] = i;
if ( cont(nivel) )
back(nivel+1);
}
}
}
int main()
{
fin>>n;
back(1);
return 0;
}