如S = "abc", 则输出:空,a, b, c, ab, ac, bc, abc,
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1005;
void dfs(char *arr, int id, int count, char* buf) {
if(arr[id] == '\0') {
buf[count] = '\0';
cout << buf << endl;
}
else {
dfs(arr, id+1, count, buf);
buf[count] = arr[id];
dfs(arr, id+1, count+1, buf);
}
}
void test(char *str) {
int len = strlen(str);
char *buf = new char[len+1];
dfs(str, 0, 0, buf);
}
int main() {
test("abcde");
return 0;
}