Pagini recente » Cod sursa (job #275978) | Cod sursa (job #3148542) | Cod sursa (job #275179) | Cod sursa (job #693199) | Cod sursa (job #1339803)
#include<stdio.h>
#define SWAP(a,b) aux=a;a=b;b=aux
void afisare(int st[],int n,FILE *qFile)
{
int i;
for(i=0;i<n;i++)
fprintf(qFile,"%i",st[i]);
fprintf(qFile,"\n");
}
void f(int st[],int u[],int n,int k)
{
int i,j,aux;
i=n-1;
while(i>0&&st[i-1]>=st[i])
{
i--;
}
if(i==0)
{
return;
}
j=n-1;
while(st[j]<=st[i-1])
{
j--;
}
SWAP(st[i-1],st[j]);
j=n-1;
while(i<j)
{
SWAP(st[i],st[j]);
i++;
j--;
}
afisare(st,n);
f(st,u,n,0);
}
int main()
{
FILE *pFile,*qFile;
pFile=fopen(permutari.in,"r");
qFile=fopen(permutari.out,"w");
int i,st[100],u[100],n;
fscanf(pFile,"%i",&n);
for(i=0;i<=n;i++)
{
st[i]=i+1;
u[i]=0;
}
afisare(st,n,qFile);
f(st,u,n,0);
fclose(pFile);
fclose(qFile);
return 0;
}