Pagini recente » Cod sursa (job #655635) | Cod sursa (job #609120) | Cod sursa (job #434794) | Cod sursa (job #3223307) | Cod sursa (job #2575904)
#include <bits/stdc++.h>
using namespace std;
const int len = 100;
int n, v[len];
bool ok;
void bkt(int x) {
if (x == n) {
for (int i = 1; i <= n; i++)
cout << v[i] << " ";
cout << "\n";
}
else
for (int i = 1; i <= n; i++) {
ok = true;
for (int j = 1; j <= x; j++)
if (v[j] == i)
ok = false;
if (ok) {
v[x + 1] = i;
bkt(x + 1);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("permutari.in", "r", stdin);
freopen("permutari.out", "w", stdout);
cin >> n;
bkt(0);
}