#include "stdio.h"
#define Max 100
struct{
int data[Max];
int top;
}stack;
int main(void){
int arry[Max],i,j;
int k,t,n,tmp,line=1,total=1;
printf("input number:");
scanf("%d",&n);
printf("output:\n");
for(i=2;i<=n;i++)
total*=i;
for(i=1;i<=n;i++){
arry[i]=i;
printf("%d",i);
}
printf(" ");
for(t=1;t<=total;t++){
i=1;
for(j=2;j<=n;j++)
if(arry[j-1]<arry[j])
i=j;
j=-1;
for(k=1;k<=n;k++)
if(arry[i-1]<arry[k]&&j<k)
j=k;
tmp=arry[i-1];
arry[i-1]=arry[j];
arry[j]=tmp;
stack.top=0;
k=i;
while(k<=n&&stack.top<Max)
stack.data[stack.top++]=arry[k++];
k=i;
while(k<=n&&stack.top>0)
arry[k++]=stack.data[--stack.top];
for(i=1;i<=n;i++)
printf("%d",arry[i]);
printf(" ");
if(line==9)
printf("\n",line=1);
else
line++;
}
return 0;
}
好久没来这了.今天心情不错.
这是我根据字典序法写的.
由于工作,N久都没来了!