摘要:以前都是用for循环解决这类题目的。。用递归输出真的是太方便了。递归输出正方形:View Code #include <stdio.h>#include <string.h>#include <algorithm>#include <stdlib.h>#include <math.h>#include <algorithm>#include <vector>#include <queue>#include <deque>#include <stack>#include <
阅读全文
摘要:输入4398,然后输出‘4’ ‘3’ ’9‘ ’8‘。。。。可以利用递归的性质#include <stdio.h>#include <string.h>#include <stdlib.h>void fun(int x ){ if (x == 0) { return ; } else fun(x / 10); printf("%c\n",x % 10 + '0');}int main( ){ int a, b; while (scanf("%d",&a) != EOF) { fun(a); }
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>int sum = 0;char ch[3] = {'L', 'R','P'};void DFS(int x, int n, int t ){ int i; if (n == t) { sum += x; return ; } for (i = 0; i < 3; i++) if( ch[i] == 'L') DFS(2 * x , n + 1, t); else if ( ch
阅读全文
摘要:#include <stdio.h>#include <string.h>int a[20], N;void fun(int n, int r){ int i, j, flag; if( r == n) { for(i = 0; i < n; i++) printf("%d ",a[i]); puts(""); return ; } else { for (i = 1; i <= n; i++) { flag = 1; for(j = 0; j < r; j++) if ( i == a[j] ) flag =
阅读全文