双递归
代码:
| 12
 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
 
 | #include <string.h>#include <iostream>
 #define MAX 10000
 using namespace std;
 
 void build(char str[],int n)
 {
 if(n==0)
 {
 cout<<"{";
 for(int i=0;i<strlen(str);++i)
 if(str[i]!=' ')
 {
 cout<<str[i];
 }
 cout<<"}"<<endl;
 }
 else
 {
 
 build(str,n-1);
 
 char newstr[5] = {' '};
 
 strcpy(newstr,str);
 
 newstr[n-1]= ' ';
 
 build(newstr,n-1);
 
 }
 }
 
 int main()
 {
 char str[MAX];
 int n;
 gets(str);
 scanf("%d",&n);
 build(str,n);
 return 0;
 }
 
 | 
 部分代码结果:
 
 请求实现过程
 参考
 https://www.cnblogs.com/orangebook/p/3537408.html?utm_source=tuicool&utm_medium=referral