标签:cout 字符串 out space turn 规律 get fj的字符串 names
1 #include<iostream> 2 using namespace std; 3 4 class print_string 5 { 6 public: 7 int get_n() 8 { 9 cin>>n; 10 return n; 11 } 12 13 void recursion(int n) //递归函数 14 { 15 if(n==1) 16 { 17 cout<<"A"; 18 } 19 else 20 { 21 recursion(n-1); 22 t=‘A‘+n-1; 23 cout<<t; 24 recursion(n-1); 25 } 26 } 27 private: 28 int n; 29 char t; //用来控制每次递归的输出 30 }; 31 32 int main(void) 33 { 34 print_string x; 35 int a; 36 a=x.get_n(); 37 x.recursion(a); 38 return 0; 39 }
在看一个用C语言写的代码:
1 # include <stdio.h> 2 3 int main() 4 5 { 6 7 int i,j; 8 9 char c[50][1000]; 10 11 int n; 12 13 char cc=‘A‘; 14 15 int count=1; 16 17 int temp; 18 19 scanf("%d", &n); 20 21 c[1][1] = ‘A‘; 22 23 c[1][2] = ‘\0‘; 24 25 for (i=2; i<=n; i++) 26 27 { 28 29 temp = count; 30 31 count = count*2+1; 32 33 for (j=1; c[i-1][j]!=‘\0‘; j++) 34 35 { 36 37 c[i][j] = c[i-1][j]; 38 39 c[i][j+temp+1] = c[i-1][j]; 40 41 42 43 } 44 45 c[i][temp+1] = ++cc; 46 47 c[i][j+temp+1] = ‘\0‘; 48 49 } 50 51 52 53 for (i=1; c[n][i]!=‘\0‘; i++) 54 55 printf("%c", c[n][i]); 56 57 printf("\n"); 58 59 60 61 return 0; 62 63 }
原文链接:https://blog.csdn.net/a237653639/article/details/21323641
标签:cout 字符串 out space turn 规律 get fj的字符串 names
原文地址:https://www.cnblogs.com/guanrongda-KaguraSakura/p/12630668.html