/******************************
作者:cncoderalex
博客:http://blog.csdn.net/cncoderalex
*******************************/
#include"Test.h"
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<string>
using namespace std;
void Helper(char *pSrc, string strSonSeq, vector<string> &vecSonSeq)
{
if (!pSrc)
return;
if (*pSrc != '\0')
{
vecSonSeq.push_back(strSonSeq);
Helper(pSrc + 1, strSonSeq, vecSonSeq);
strSonSeq.push_back(*pSrc);
vecSonSeq.push_back(strSonSeq);
Helper(pSrc + 1, strSonSeq, vecSonSeq);
}
}
void GetSonSequence(char *pSrc, vector<string> &vecSonSeq)
{
string strSonSeq;
Helper(pSrc, strSonSeq, vecSonSeq);
sort(vecSonSeq.begin(), vecSonSeq.end());
vector<string>::iterator it = unique(vecSonSeq.begin(), vecSonSeq.end());
vecSonSeq.erase(it, vecSonSeq.end());
}
int main()
{
printf("http://blog.csdn.net/cncoderalex");
printf("\n");
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
char *pSrc = "abcd";
vector<string> vecSonSeq;
GetSonSequence(pSrc, vecSonSeq);
for (auto item : vecSonSeq)
{
cout << item << endl;
}
system("pause");
return 0;
}
求字符串的所有字序列(暴力法)
最新推荐文章于 2022-12-05 17:28:13 发布