程序代码:
#include <iostream> using namespace std; const size_t MAX=6; unsigned int array[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; void _swap(unsigned int &a, unsigned int &b) { unsigned int temp = a; a = b; b = temp; } void _show_x(const size_t x) { //输出横向 for (size_t i=1; i<=MAX; ++i) { if (i==array[x]) { cout << 1 << ' '; } else { cout << 0 << ' '; } if (!(i%3)) { cout << 0 << ' '; } } cout << endl; } void _show() { static size_t counter = 1; cout << "counter = " << counter << endl; counter++; for (size_t i=1; i<=MAX; ++i) { _show_x(i-1); if (!(i%3)) { for (size_t j=1; j<=MAX; ++j) { if (!(j%3)) { cout << 0 << ' '; } cout << 0 << ' '; } cout << endl; //cout << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl; } } cout << endl; } void _function(size_t index) { if (index == MAX-1) { _show(); } else { for(size_t i=index; i<MAX; ++i) { _swap(array[index], array[i]); _function(index+1); _swap(array[index], array[i]); } } } int main(void) { freopen("text.txt", "w", stdout); _function(0); return 0; }