Pagini recente » Cod sursa (job #71286) | Cod sursa (job #2889739) | Cod sursa (job #722995) | Cod sursa (job #2285255) | Cod sursa (job #2244214)
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <assert.h>
#include <queue>
using LL = long long;
using ULL = int long long;
const std::string _problemName = "permutari";
namespace std {
std::ifstream fin(_problemName + ".in");
std::ofstream fout(_problemName + ".out");
}
#define USE_FILES
#ifdef USE_FILES
#define cin fin
#define cout fout
#endif
class Generator {
public:
void reset(int n) {
n_ = n;
current_.resize(n);
used_.resize(n);
std::fill(used_.begin(), used_.end(), false);
}
void generate(int n) {
reset(n);
generateImpl(0);
}
private:
void generateImpl(int pos) {
if (pos >= n_) {
output();
return;
}
for (int newVal = 0; newVal < n_; ++newVal) {
if (used_[newVal]) {
continue;
}
current_[pos] = newVal;
generateImpl(pos + 1);
}
}
void output() {
for (auto i : current_) {
std::cout << i + 1 << ' ';
}
std::cout << '\n';
}
private:
int n_;
std::vector<int> current_;
std::vector<bool> used_;
};
int main() {
int n;
std::cin >> n;
Generator().generate(n);
return 0;
}