废话不多说,直接上代码,谁测试,谁知道

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(全排列)的更多相关文章

  1. next_permutation() 全排列函数

    next_permutation() 全排列函数 这个函数是STL自带的,用来求出该数组的下一个排列组合 相当之好用,懒人专用 适用于不想自己用dfs写全排列的同学(结尾附上dfs代码) 洛谷oj可去 ...

  2. next_permutation(全排列算法)

    STL提供了两个用来计算排列组合关系的算法,分别是next_permutation和prev_permutation.首先我们必须了解什么是"下一个"排列组合,什么是"前 ...

  3. STL - next_permutation 全排列函数

    学习: http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html http://blog.csdn.net/ac_gibson/article/deta ...

  4. STL next_permutation 全排列

    调用方法: ]={,,,}; )){ ;i<;i++) printf("%d ",arr[i]); puts(""); } 测试效果: 注:可以看到1 2 ...

  5. 嵊州D2T2 八月惊魂 全排列 next_permutation()

    嵊州D2T2 八月惊魂 这是一个远古时期的秘密,至今已无人关心. 这个世界的每个时代可以和一个 1 ∼ n 的排列一一对应. 时代越早,所对应的排列字典序就越小. 我们知道,公爵已经是 m 个时代前的 ...

  6. poj3187-Backward Digit Sums(枚举全排列)

    一,题意: 输入n,sum,求1~n的数,如何排列之后,相邻两列相加,直到得出最后的结果等于sum,输出1~n的排列(杨辉三角)  3 1 2 4 //1~n 全排列中的一个排列  4 3 6  7 ...

  7. 【字母全排列】 poj 1256

    深搜   注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...

  8. 全排列问题(递归&非递归&STL函数)

    问题描述: 打印输出1-9的所有全排序列,或者打印输出a-d的全排列. 思路分析: 将每个元素放到余下n-1个元素组成的队列最前方,然后对剩余元素进行全排列,依次递归下去. 比如:1 2 3 为例首先 ...

  9. USACO2006 Backward Digit Sums /// 全排列 oj24212

    题目大意: 给出杨辉三角的顶点值M和底边数的个数 N (1 ≤ N ≤ 10) ,求出底边各个数的值,其中各个数范围都为1 ~ N 当N=4,M=16时可能是这样的   3   1   2   4  ...

  10. poj 1027 Ignatius and the Princess II全排列

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

随机推荐

  1. C++ STL 全排列函数

    C++  全排列函数...一听名字就在<algorithm>中... 首先第一个说的是next_permutation: #include <algorithm> bool n ...

  2. /etc/profile、~/.bash_profile等几个文件的执行过程

    /etc/profile.~/.bash_profile等几个文件的执行过程  摘自:http://blog.chinaunix.net/uid-14735472-id-3190130.html 分类 ...

  3. ngix 创建新的网站

    1. 进入ngix 的目录的conf 目录 的 vhosts 2. 复制一份新的v2.edc.com.conf 3. server_name : v2.edc.com root :  /ali/... ...

  4. (2)WePHP 控制器与使用模板

    <?php class C_index extends Action { public function __initialize() { echo"自动执行"; } pub ...

  5. javascript总结41:表格全选反选,经典案例详解

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. 用php导入10W条+ 级别的csv大文件数据到mysql。导出10W+级别数据到csv文件

    转自:http://blog.csdn.net/think2me/article/details/12999907 1. 说说csv 和 Excel 这两者都是我们平时导出或者导入数据一般用到的载体. ...

  7. 正则表达式(javascript)

    在开发过程中要要把一个css中的平移的x,y提取出来 ,正好把正则表达式学习了一下 'fsdfsdfsdf300pxfdsfd200pxfsdfsdf100px'  找出里面 px前面的数字: 经查资 ...

  8. CentOS 7.2安装gitlab-ce

    国内网络原因,gitlab-ce安装包可以在清华大学开源网站镜像站下载:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ [root@gitlab ~]# ...

  9. C#基础入门 一

    C#基础入门 一 基本输入输出函数 简单程序输出helloworld using System;//引入System库 namespace MainClass { class MainClass { ...

  10. Nexys4 DDR MIG控制器引脚文件

    目前网上只有ucf文件,vivado不兼容ucf格式 使用c++字符串转换的xdc格式代码 set_property -dict { PACKAGE_PIN R7 IOSTANDARD SSTL18_ ...