Cod sursa(job #2800890)
Utilizator | Data | 14 noiembrie 2021 12:52:19 | |
---|---|---|---|
Problema | Generare de permutari | Scor | 80 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.67 kb |
#include <bits/stdc++.h>
using namespace std;
int st[9], top=0, n;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
void Afisare()
{
for(int i=1;i<=n;i++)
fout<<st[i]<<" ";
fout<<endl;
}
bool Verifica(int x, int top)
{
for(int i=1;i<=top;++i)
if(st[i] == x) return false;
return true;
}
void Back(int top)
{
if(top==n+1) Afisare();
else
{
for(int i=1;i<=n;++i)
if(Verifica(i, top-1))
{
st[top]=i;
Back(top+1);
}
}
}
int main()
{
fin>>n;
fin.close();
Back(1);
return 0;
}