Pagini recente » Cod sursa (job #874607) | Cod sursa (job #1525018) | Cod sursa (job #1763283) | Cod sursa (job #957086) | Cod sursa (job #1104251)
#include <iostream>
#include <fstream>
#define nmax 9
using namespace std;
ifstream in("permutari.in");
ofstream out("permutari.out");
int n,k;
short st[nmax];
void w(){
for (int j=1; j<=n; j++)
out << st[j] << " ";
out << endl;
}
bool check(int k){
for (int i=1; i<k; i++)
if (st[i]==st[k]) return false;
return true;
}
void back(int k){
for (int i=1; i<=n; i++){
st[k]=1;
if (check(k)){
if (k==n) w();
else back(k+1);
}
}
}
int main(){
in >> n;
back(1);
return 0;
}