1 2 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 43 44 45 46 47 48 49
|
$ cat baz.cpp
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
constexpr int DIMX=8, DIMY=3, DIMZ=2;
void foo( int arr[DIMX][DIMY][DIMZ], int depth, const string &result ) {
if ( depth == DIMX ) {
cout << result << endl;
return;
}
for ( int i = 0 ; i < DIMY ; i++ ) {
if ( arr[depth][i][0] ) {
ostringstream os;
os << "[" << arr[depth][i][0] << "," << arr[depth][i][1] << "]";
string t = result + (result.length() > 0 ? "," : "") + os.str();
foo(arr,depth+1,t);
} else {
return;
}
}
}
int main()
{
int arr[DIMX][DIMY][DIMZ] =
{ {{1,2},{22,23},{33,34}},
{{3,4},{0,0},{0,0}},
{{5,6},{7,8},{0,0}},
{{9,10},{0,0},{0,0}},
{{11,12},{0,0},{0,0}},
{{13,14},{0,0},{0,0}},
{{15,16},{0,0},{0,0}},
{{17,18},{0,0},{0,0}}
};
foo(arr,0,"");
return 0;
}
$ g++ -std=c++11 baz.cpp
$ ./a.out
[1,2],[3,4],[5,6],[9,10],[11,12],[13,14],[15,16],[17,18]
[1,2],[3,4],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18]
[22,23],[3,4],[5,6],[9,10],[11,12],[13,14],[15,16],[17,18]
[22,23],[3,4],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18]
[33,34],[3,4],[5,6],[9,10],[11,12],[13,14],[15,16],[17,18]
[33,34],[3,4],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18]
| |