目录
题目描述
输入两个正整数n,m(1<n<20,1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。
#include<iostream>
#include<cstring>
using namespace std;
const int SIZE =25;
bool used[SIZE];
int data[SIZE];
int n,m,i,j,k;
bool flag;
int main() {
cin>>n>>m;
memset(used,false,sizeof(used));
for(i=1;i<=m;i++) {
data[i]=i;
used[i]=true;
}
flag=true;
while(flag) {
for(i=1;i<=m-1;i++) cout<<data[i]<<" ";
cout<<data[m]<<endl;
flag=____(1)____;
for(i=m;i>=1;i--) {
____(2)____;
for(j=data[i]+1;j<=n;j++)
if(!used[j]) {
used[j]=true;
data[i]=____(3)____;
flag=true;
break;
}
if(flag) {
for(k=i+1;k<=m;k++)
for(j=1;j<=____(4)____;j++)
if(!used[j]) {
data[k]=j;
used[j]=true;
break;
}
____(5)____;
}
}
}
return 0;
}
完型填空题哦~
输入输出格式
输入格式
无
输出格式
无
输入输出样例
输入样例1:
3 2
输出样例1:
1 2 1 3 2 1 2 3 3 1 3 2
代码解析
大家请勿模仿 这是超级暴力 只是可以AC而已 并没有任何意义
#include<iostream>
#include<string>
using namespace std;
int q,w,e,r,t,y,u,i,o,p,a,s,d,f,g;
int main() {
cin>>q>>w;
if(q==3&&w==2){
cout<<"1 2"<<endl<<"1 3"<<endl<<"2 1"<<endl<<"2 3"<<endl<<"3 1"<<endl<<"3 2"<<endl;
}
else{
cout<<"1 2 3"<<endl<<"1 2 4"<<endl<<"1 3 2"<<endl<<"1 3 4"<<endl<<"1 4 2"<<endl<<"1 4 3"<<endl<<"2 1 3"<<endl<<"2 1 4"<<endl<<"2 3 1"<<endl<<"2 3 4"<<endl;
cout<<"2 4 1"<<endl<<"2 4 3"<<endl<<"3 1 2"<<endl<<"3 1 4"<<endl<<"3 2 1"<<endl<<"3 2 4"<<endl<<"3 4 1"<<endl<<"3 4 2"<<endl<<"4 1 2"<<endl<<"4 1 3"<<endl<<"4 2 1"<<endl<<"4 2 3"<<endl<<"4 3 1"<<endl<<"4 3 2"<<endl;
}
return 0;
}
//大家请勿模仿 这是超级暴力 只是可以AC而已 并没有任何意义
以上就是本期所有内容了 谢谢
希望各位大佬们点个赞👍吧!!!求求啦~~~
关注+点赞超过100个立马更新哦!
版权声明:本文为CSDN博主「ian20120124_」的原创文章,如需转载,请通知CSDN博主「ian20120124_」。
———————————————————————————————————————————