Cod sursa(job #1132316)
| Utilizator | Data | 2 martie 2014 22:57:43 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.95 kb |
#include <fstream>
using namespace std;
int n,k,altul, sol[9],i;
int valid()
{
int j;
for (j=1;j<k;j++)
if (sol[j] == sol[k])
return 0;
return 1;
}
int main()
{
ifstream fin;
ofstream fout;
fin.open("permutari.in");
fout.open("permutari.out");
fin>>n;
k=1;
while (k)
{
do
{
if (sol[k]<n)
{
sol[k]++;
altul = 1;
}
else
altul = 0;
}
while (altul && !valid());
if (altul)
{
if (k==n)
{
for (i=1;i<=k;i++)
fout<<sol[i]<<" ";
fout<<endl;
}
else
{
k++;
sol[k]=0;
}
}
else
k--;
}
fin.close();
fout.close();
}
