Cod sursa(job #2785411)
Utilizator | Data | 18 octombrie 2021 17:32:46 | |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.64 kb |
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n, k;
vector<int> sol;
void permutations()
{
if (sol.size() == n)
{
for (int it : sol)
{
fout << it << " ";
}
fout << "\n";
return;
}
for (int i = 1; i <= n; ++i)
{
if (find(sol.begin(), sol.end(), i) == sol.end())
{
sol.push_back(i);
permutations();
sol.pop_back();
}
}
}
int main()
{
fin >> n;
permutations();
return 0;
}