您的位置:首页 > 其它

经典名师---字典顺序输出全排列

2007-06-05 12:30 260 查看
#include<iostream>
#include<math.h>
#define MAXNUM 6
using namespace std;
int SWAPI(int &,int &);
float computer(float,float,int);

int main()
{
int perm[MAXNUM];
int last,left,right,i,j;
cout<<"Pleaset input 4 number"<<endl;
for(i=0;i<MAXNUM;i++)//初始入perm[i]
{
perm[i]=i+1;
}
for(last=0;last>=0;)
{
for(j=0;j<MAXNUM;j++)//输出结果
{
cout<<perm[j]<<" ";
}
cout<<endl;
for(last=MAXNUM-2;last>=0&&perm[last]>perm[last+1];last--);//从后往前找perm[i]<perm[i+1]
if(last<0)//没找到
{
break;
}
for(j=MAXNUM-1;perm[last]>perm[j];j--);//从后往前找perm[i]<perm[j]
SWAPI(perm[last],perm[j]);//交换
for(left=last+1,right=MAXNUM-1;left<right;left++,right--)
{
SWAPI(perm[left],perm[right]);

}
}
cin>>i;
return 0;
}

int SWAPI(int &x,int &y)
{
int t;
t=x;
x=y;
y=t;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  float input
相关文章推荐