Pagini recente » Cod sursa (job #2892712) | Cod sursa (job #2937498) | Cod sursa (job #2862366) | Cod sursa (job #2344798) | Cod sursa (job #2270727)
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
ifstream in("permutari.in");
ofstream out("permutari.out");
int folosite[8];
int iesit[8];
bool check(int i,int index){
for(int k=index-1;k>=0;k--){
if(folosite[k]==i)
return false;
}
return true;
}
void perm(int n,int now,int index_acum)
{
if(now==n)
{
for(int i=0;i<now;i++){
out<<iesit[i]<<" ";
}
out<<"\n";
return;
}
for(int i=1; i<=n; i++)
{
if(check(i,now))
{
iesit[now]=i;
folosite[now]=i;
perm(n,now+1,i);
}
}
}
int main()
{
int n;
in>>n;
perm(n,0,0);
}