next_permutation(全排列)
废话不多说,直接上代码,谁测试,谁知道
C++:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
string str;
cin>>str;
sort(str.begin(),str.end());
cout<<str<<endl;
while(next_permutation(str.begin(),str.end()))
{
cout<<str<<endl;
}
return 0;
}
C:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
//freopen("input.txt","r",stdin);
char str[1000];
gets(str);
int length = strlen(str);
sort(str,str+length);
puts(str);
while(next_permutation(str,str+length)){
puts(str);
}
return 0;
}
测试数据:zxgffeeddb
C语言版本的本机运行了23.695s,C++版本的本机运行了58.861s……C的效率比C++的效率高了一倍多……
C语言牛逼!
next_permutation(全排列)的更多相关文章
- next_permutation() 全排列函数
next_permutation() 全排列函数 这个函数是STL自带的,用来求出该数组的下一个排列组合 相当之好用,懒人专用 适用于不想自己用dfs写全排列的同学(结尾附上dfs代码) 洛谷oj可去 ...
- next_permutation(全排列算法)
STL提供了两个用来计算排列组合关系的算法,分别是next_permutation和prev_permutation.首先我们必须了解什么是"下一个"排列组合,什么是"前 ...
- STL - next_permutation 全排列函数
学习: http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html http://blog.csdn.net/ac_gibson/article/deta ...
- STL next_permutation 全排列
调用方法: ]={,,,}; )){ ;i<;i++) printf("%d ",arr[i]); puts(""); } 测试效果: 注:可以看到1 2 ...
- 嵊州D2T2 八月惊魂 全排列 next_permutation()
嵊州D2T2 八月惊魂 这是一个远古时期的秘密,至今已无人关心. 这个世界的每个时代可以和一个 1 ∼ n 的排列一一对应. 时代越早,所对应的排列字典序就越小. 我们知道,公爵已经是 m 个时代前的 ...
- poj3187-Backward Digit Sums(枚举全排列)
一,题意: 输入n,sum,求1~n的数,如何排列之后,相邻两列相加,直到得出最后的结果等于sum,输出1~n的排列(杨辉三角) 3 1 2 4 //1~n 全排列中的一个排列 4 3 6 7 ...
- 【字母全排列】 poj 1256
深搜 注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...
- 全排列问题(递归&非递归&STL函数)
问题描述: 打印输出1-9的所有全排序列,或者打印输出a-d的全排列. 思路分析: 将每个元素放到余下n-1个元素组成的队列最前方,然后对剩余元素进行全排列,依次递归下去. 比如:1 2 3 为例首先 ...
- USACO2006 Backward Digit Sums /// 全排列 oj24212
题目大意: 给出杨辉三角的顶点值M和底边数的个数 N (1 ≤ N ≤ 10) ,求出底边各个数的值,其中各个数范围都为1 ~ N 当N=4,M=16时可能是这样的 3 1 2 4 ...
- poj 1027 Ignatius and the Princess II全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
随机推荐
- turntable
1.业务流程 2.80001代码逻辑 3.80002代码逻辑 4抽奖概率计算
- linux ubuntu 各目录大小
/home 45k /bin 8.7M /lib 370M /mnt 4.1k /run 36k /sbin 11M /tmp 41k /usr/share 770M
- Redis初学笔记
1.官网概述 Redis is an open source (BSD licensed), in-memory data structure store, used as database, cac ...
- jdk、jre、jvm的区别联系
jdk包括以下三个东西: D:\Program Files\jdk1.7.0_21\bin\javac.exe和java.exe D:\Program Files\jdk1.7.0_21\jre D: ...
- Tag recommendaion... 论文中的小例子,使用HOSVD算法推荐
本文内容来自于论文:Tag recommendations based on tensor dimensioanlity reduction 在社会标签系统中,存在三元关系,用户-物品-标签.这些数据 ...
- org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
查看日志信息: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/app/a ...
- Cannot evaluate the property expression "$([MSBuild]::ValueOrDefault('$(VCTargetsPath)','$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\V140\'))" found at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuil
Cannot evaluate the property expression "$([MSBuild]::ValueOrDefault('$(VCTargetsPath)','$(MSBu ...
- 搭建python+PyQt+Eric平台
搭建python+PyQt+Eric平台 预备安装程序: 2.1.下载Python3.2 官方网站:http://www.python.org/ 下载地址:http://www.python.org/ ...
- HBase介绍(2)---数据存储结构
在本文中的HBase术语:基于列:column-oriented行:row列组:column families列:column单元:cell 理解HBase(一个开源的Google的BigTable实 ...
- 解决Struts2拦截器的对于参数传递无效问题
今天做项目时,使用拦截器对用户权限检查.拦截器本身没有问题,可是实现权限拦截,但是传递的参数全部都无效了.搞了很久,由于对拦截器的内部机制不是特别熟悉,所以重新研读了一下Struts2的拦截器.找到了 ...