Pagini recente » Cod sursa (job #61898) | Cod sursa (job #1034557) | Cod sursa (job #1255327) | Cod sursa (job #1373642) | Cod sursa (job #2538760)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n;
short sol[9];
bool Valid(int pos){
if(pos>n) return false;
for(int j=1; j<pos; j++){
if(sol[j]==sol[pos]) return false;
}
return true;
}
bool Solutie(int pos){
if(pos==n) return true;
else return false;
}
void Afisare(){
for(int i=1; i<=n; i++){
fout<<sol[i]<<" ";
}
fout<<endl;
}
void bkt(int pos){
for(int i=1; i<=n; i++){
sol[pos] = i;
if(Valid(pos)){
if(Solutie(pos)){
Afisare();
}
else bkt(pos+1);
}
}
}
int main(int argc, char** argv) {
fin>>n;
bkt(1);
}