Pagini recente » Cod sursa (job #180455) | Cod sursa (job #690219) | Istoria paginii runda/oji_xi | Cod sursa (job #2303335) | Cod sursa (job #1387475)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int st[100], n;
void init (int p){
for (int i=1; i<=25; i++)
st[i]=0;
}
bool valid(int p){
bool ok=true;
for (int i=1; i<=p-1; i++)
if (st[i]==st[p]) ok=false;
return ok;
}
void tipar(int p){
for (int i=1; i<=p; i++)
g<<st[i]<<" ";
g<<endl;
}
void backk(int p){
p=1;
st[p]=0;
while (p>0){
if (st[p]<n) { st[p]=st[p]+1;
if (valid(p)==true)
if (p==n) tipar(p);
else {
p++;
st[p]=0;
}
}
else p--;
}
}
int main()
{ f>>n;
init(n);
backk(1);
return 0;
}