Pagini recente » Cod sursa (job #2258213) | Cod sursa (job #2399941) | Cod sursa (job #1266823) | Cod sursa (job #31417) | Cod sursa (job #1551100)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int st[20], n;
void Afisare()
{
for(int i = 1; i <= n; i++)
fout << st[i] << " ";
fout <<"\n";
}
inline bool Valid(int top, int i)
{
int j;
for(j = 1; j < top; j++)
if(st[j] == i) return false;
return true;
}
inline void Back(int top)
{
int i;
if(top == n + 1) Afisare();
else for(i = 1; i <= n; i++)
if(Valid(top, i))
{
st[top] = i;
Back(top + 1);
}
}
int main()
{
fin >> n;
fin.close();
Back(1);
fout.close();
return 0;
}