Pagini recente » Cod sursa (job #68144) | Cod sursa (job #445778) | Cod sursa (job #2215919) | Cod sursa (job #2925562) | Cod sursa (job #2437625)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("permutari.in");
ofstream fout ("permutari.out");
int a[9], n;
bool check(int n)
{
for(int i = 1; i < n; ++i) if(a[i] == a[n]) return 0;
return 1;
}
int solve(int k)
{
for(int i = 1; i <= n; ++i) {
a[k] = i;
if(check(k)) {
if(k != n) solve(k + 1);
else {
for(int j = 1; j <= n; ++j) fout << a[j] << " ";
fout << "\n";
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
fin >> n;
solve(1);
return 0;
}