Pagini recente » Cod sursa (job #840015) | Cod sursa (job #2291482) | Cod sursa (job #1203562) | Cod sursa (job #287181) | Cod sursa (job #2909658)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
const int MAX_SIZE = 9;
int n;
bool used[MAX_SIZE];
void generatePermutations(int i, int permutation[MAX_SIZE]) {
if (i == n + 1) {
for (int i = 1; i <= n; ++i) {
fout << permutation[i] << " ";
}
fout << "\n";
return;
}
for (char c = 1; c <= n; ++c) {
if (used[c] == 0) {
permutation[i] = c;
used[c] = 1;
generatePermutations(i + 1, permutation);
used[c] = 0;
}
}
}
int main() {
fin >> n;
int permutation[MAX_SIZE];
generatePermutations(1, permutation);
}