string_perm_example.cpp
来自「利用递归查找数字的排列组合 使用了STL技术」· C++ 代码 · 共 51 行
CPP
51 行
// recvperm.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
void string_permutation( std::string& orig, std::string& perm )
{
if( orig.empty() )
{
std::cout<<perm<<std::endl;
return;
}
for(int i=0;i<orig.size();++i)
{
std::string orig2 = orig;
orig2.erase(i,1);
std::string perm2 = perm;
perm2 += orig.at(i);
string_permutation(orig2,perm2);
}
}
int main()
{
std::string orig="ABCDE";
std::string perm;
string_permutation(orig,perm);
cout<<"Complete!"<<endl;
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?