Cod sursa(job #1011062)
Utilizator | Data | 16 octombrie 2013 09:38:58 | |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int n, v[10];
void afis() {
for(int i=1;i<=n;i++)
g<<v[i]<<" ";
g<<"\n";
}
void bkt( int pos ) {
if (pos==n+1)
afis();
else {
for(int i=1;i<=n;i++) {
int ok=1;
for(int j=1;j<pos;j++)
if(v[j]==i)
ok=0;
if(ok==1) {
v[pos]=i;
bkt(pos+1);
}
}
}
}
int main() {
f>>n;
bkt(1);
}