Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
74 lines (67 loc) · 1.41 KB

File metadata and controls

74 lines (67 loc) · 1.41 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
71
72
73
74
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
#include<assert.h>
//Arrangement
//Combination
//////////--------------------递归-------------
void Combination(char *string ,int number,vector<char> &result);
void Combination(char *string)
{
assert(string != NULL);
vector<char> result;
int i , length = strlen(string);
// for(i = 1 ; i <= length ; ++i)
Combination(string , 3 ,result);
}
void Combination(char *string ,int number , vector<char> &result)
{
assert(string != NULL);
if(number == 0)
{
static int num = 1;
printf("第%d个组合\t",num++);
vector<char>::iterator iter = result.begin();
for( ; iter != result.end() ; ++iter)
printf("%c",*iter);
printf("\n");
return ;
}
if(*string == '\0')
return ;
result.push_back(*string);
Combination(string + 1 , number - 1 , result);
result.pop_back();
Combination(string + 1 , number , result);
}
//////////----------------非递归-----------------
void print_subset(char* str,int n , int s)
{
int i;
int flag=0;
char tmp[4]="";
for(i = 0 ; i < n ; ++i)
if(s&(1<<i))// 判断s的二进制中哪些位为1,即代表取某一位
{
tmp[flag++]=str[i];
}
if(flag == 3)
printf("%d:%s\n",s,tmp);
}
void subset(char * str,int n)
{
int i;
for(i= 0 ; i < (1<<n) ; ++i)
{
print_subset(str,n,i);
}
}
int main(void)
{
char str[] = "abcdef";
int n = strlen(str);
Combination(str);
subset(str,n);
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.