用递归拆分一个数

#include<iostream>using namespace std;int *arr;int n;void print(){ cout << n << " = " << arr[0]; int i = 1; while(arr[i]) cout << " + " << arr[i++]; cout << endl;}void process(int arr[], int max, int n)//n为剩余值,max为当前位置可以为最大的数。{ arr[0] = max < n ? max : n; if(n == 0) ...
默认分类 | 2010-10-12 09:11 | 阅读 1029 次 | 评论 0 条

递归打印菱形

#include<iostream>using namespace std;void printchar(int n, char ch){ for(int i = 0; i != n; ++i) cout << ch;}void fun(int i, int j, int n){ printchar(i,' '); printchar(j,'*'); cout << endl; if(j<n) { fun(i-1,j+2,n); printchar(i,' '); printchar(j,'*')...
默认分类 | 2010-10-12 09:09 | 阅读 1320 次 | 评论 0 条

Win32 控制台应用程序清屏函数

/* Standard error macro for reporting API errors */ #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}void cls( HANDLE hConsole ){ COORD coordScreen = { 0, 0 }; /* here's where we'll home the ...
默认分类 | 2010-10-05 11:10 | 阅读 3014 次 | 评论 0 条

组合生成算法

#include<iostream>using namespace std;void print(const int A[], const int B[], int Bn){ for (int i = 0; i != Bn; ++i) cout << A[*(B+i)];}bool fun(int B[], int Bn, int An)//处理进位{ int x = Bn-1; while(B[x] > x+An-Bn) { if(x == 0) return false; B[x-1] += 1; --x...
默认分类 | 2010-10-01 14:04 | 阅读 1571 次 | 评论 1 条
浏览31139次