Cod sursa(job #2573113)
| Utilizator | Data | 5 martie 2020 15:53:05 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <fstream>
#define ios ios_base::sync_with_stdio(false);
using namespace std;
ifstream cin("permutari.in");
ofstream cout("permutari.out");
int s[13],n;
bool valid(int x){
for (int k=1;k<x;k++) if (s[k]==s[x]) return 0;
return 1;
}
void afis(){
for (int t=1;t<=n;t++) cout<<s[t]<<" ";
cout<<'\n';
}
void gen(int j){
for (int i=1;i<=n;i++){
s[j]=i;
if (valid(j))
if (j==n) afis();
else gen(j+1);
}
}
int main()
{
cin.tie(0);
cout.tie(0);
cin>>n;
gen(1);
return 0;
}
