Pagini recente » Cod sursa (job #1378184) | Cod sursa (job #1492065) | Cod sursa (job #2823978) | Cod sursa (job #827492) | Cod sursa (job #1087131)
#include<fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int k,q,s[100],n,i;
int verificare(int x)
{
q=1;
for(i=1;i<x;i++)
{
if(s[x]==s[i])
q=0;
}
return q;
}
void afisare()
{
for(i=1;i<=k;i++)
g<<s[i]<<" ";
g<<'\n';
}
int main()
{
f>>n;
k=1;
s[k]=0;
while(k>0)
{
q=0;
while(q==0&&s[k]+1<=n)
{
s[k]++;
q=verificare(k);
}
if(q)
if(k==n)
afisare();
else
k++,s[k]=0;
else
k--;
}
}