Pagini recente » Cod sursa (job #3157475) | Cod sursa (job #594453) | Cod sursa (job #451016) | Cod sursa (job #230001) | Cod sursa (job #2574523)
#include <bits/stdc++.h>
using namespace std;
const int len = 100;
int n, v[len];
bool ok;
void bkt(int p) {
if (p == 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 <= p; j++)
if (v[j] == i)
ok = false;
if (ok) {
v[p + 1] = i;
bkt(p + 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);
}