-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrCombination.cpp
More file actions
71 lines (62 loc) · 1.33 KB
/
StrCombination.cpp
File metadata and controls
71 lines (62 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// StrCombination.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string.h>
#include <windows.h>
using namespace std;
static int nSum = 0;
void StrCombination(char *pStr, int num, vector<char>&Result);
//void Print(vector<char>&Result);
void StrStoken(char *pStr)
{
if (NULL == pStr && strlen(pStr) <= 0)return;
int length = strlen(pStr);
vector<char>v_Result;
for (int iSize = 1; iSize <= length; iSize++)
{
StrCombination(pStr, iSize, v_Result);
}
cout << v_Result.size() << endl;
}
void StrCombination(char *pStr, int num, vector<char>&Result)
{
if (nullptr == pStr && strlen(pStr) <= 0) return;
if (0 == num)
{
static int nCount = 1;
printf("第%d个组合\t", nCount++);
vector<char> ::iterator it = Result.begin();
for (; it != Result.end(); it++)
{
printf("%c", *it);
//
//nSum++;
}
nSum++;
cout << endl;
return;
}
if ('\0' == *pStr)return;
Result.push_back(*pStr);
StrCombination(pStr + 1, num - 1, Result);
Result.pop_back();
StrCombination(pStr + 1, num, Result);
}
//void Print(vector<char>&Result)
//{
// vector<char>::iterator it = Result.begin();
// for (;it!=Result.end(); it++)
// {
// cout << *it << endl;
// }
//}
int main()
{
char test[] = "abcde";
StrStoken(test);
cout << nSum << endl;
system("pause");
return 0;
}