字符串全排列
2015-08-29 12:02
218 查看
字符串全排列
问题:给定字符串S,生成该字符串的全排列。方法:依次从字符串中取出一个字符作为最终排列的第一个字符,对剩余字符组成的字符串生成全排列,最终结果为取出的字符和剩余子串全排列的组合:
#include <iostream> #include <string> using namespace std; void permute(string prefix, string str) { if(str.length() == 0) cout << prefix << endl; else { for(int i = 0; i < str.length(); i++) permute1(prefix+str[i], str.substr(0,i)+str.substr(i+1,str.length())); } } int main(){ permute("",s); return 0; }
具体过程如图所示:
相关文章推荐
- 线程池模型
- leetcode 104 Maximum Depth of Binary Tree(难易度:Easy)
- CCF 命令行窗口
- (2.3.9)用户态和内核态的概念区别
- 使用 Bootstrap 和 HTML5 Boilerplate 开始一个项目
- android java.lang.IllegalStateException异常产生的原因及解决办法 Offending field: mSpans
- 如何在windows7上安装启明星系统。
- MySQL数据库编码格式问题
- UICollectionView flowlauout 瀑布流效果
- 杭电 HDU ACM 1150 Machine Schedule(二分匹配)
- VS2005中乱码问题
- 网络抓包以及进行简单数据分析
- (转)FCKeditor文本编辑器的使用方法
- Sicily 1419 On the run 动态规划的应用
- C#异步SOCKET发送帮肋类,支持UDP,TCP
- [软件操作]记一次基于Unity的Profiler性能分析
- android再按一次退出程序提示
- LoadRunner11学习记录五
- 【设计模式】之 透过工厂方法看 抽象类和接口
- 【设计模式】之 透过工厂方法看 抽象类和接口