Pagini recente » Cod sursa (job #3215667) | Cod sursa (job #1338696) | Cod sursa (job #435219) | Cod sursa (job #2920415) | Cod sursa (job #2634039)
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int p[10],i,j,n,st,dr,gasit,nr;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
p[i]=i;
do
{ nr++;
for(i=1;i<=n;i++)
fout<<p[i]<<" ";
fout<<'\n';
gasit=0;
i=n-1;
while(gasit==0 and i>=1)
if(p[i]>p[i+1]) i--;
else gasit=1;
if(gasit){
j=n;
while(p[j]<p[i]) j--;
swap(p[j],p[i]);
st=i+1;
dr=n;
while(st<dr){
swap(p[st],p[dr]);
st++;
dr--;
}
}
}while (gasit==1 and nr<15000);
return 0;
}