next_permutation
来源:互联网 发布:photoshopcs6 for mac 编辑:程序博客网 时间:2024/05/20 05:09
输入
2
aAb
abc
输出
AabAba
aAb
abA
bAa
baA
abc
acb
bac
bca
cab
cba
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;int comp(char a,char b){ if(tolower(a)!=tolower(b)) return tolower(a)<tolower(b); else return a<b;}int main(){ char ch[20]; int n; scanf("%d",&n); while(n--) { scanf("%s",ch); sort(ch,ch+strlen(ch),comp); do { printf("%s\n",ch); } while(next_permutation(ch,ch+strlen(ch))); } return 0;}aed
ade
aed
dae
dea
ead
eda
#
#include<stdio.h>#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){ string line; while(cin>>line) { if(line=="#") break; sort(line.begin(),line.end()); do { cout<<line<<endl; } while(next_permutation(line.begin(),line.end())); } return 0;}1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
#include<stdio.h>#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){ int a[3]; a[0]=1; a[1]=2; a[2]=3; do { printf("%d %d %d\n",a[0],a[1],a[2]); } while(next_permutation(a,a+3)); return 0;}
1 2 3
2 1 3
#include<stdio.h>#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){ int a[3]; a[0]=1; a[1]=2; a[2]=3; do { printf("%d %d %d\n",a[0],a[1],a[2]); } while(next_permutation(a,a+2));//2指要进行排列的长度,只排列a[0]和a[1],a[3]不进行排序 return 0;}
2 1 3
#include<stdio.h>#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){ int a[3]; a[0]=1; a[1]=2; a[2]=3; int t=0; do { t++; if(t==3)//只输出第三组数据 printf("%d %d %d\n",a[0],a[1],a[2]); } while(next_permutation(a,a+3)); return 0;}
0 0
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- 赢在职场-WEB全栈开发-1-7margin
- 茫无头绪的瞎侃
- swift数据类型
- 第10、11周项目5:摩托车继承自行车和机动车
- Java多线程
- next_permutation
- linux动态库及静态库的制作 和makefile 的简单编写
- 第109讲: Spark Streaming电商广告点击综合案例动态黑名单基于数据库MySQL的真正操作代码实战
- Java throws以及throw疑惑解析
- 脉冲式和相位式激光测距
- mysql常见问题
- 金融新闻
- Codeforces Round #346 (Div. 2)Round House
- leetcode 1 Two Sum(在无序数组中找两个数之和与目标值相等,两种方法)