diff --git a/lab08/03.cpp b/lab08/03.cpp new file mode 100644 index 0000000..e49f382 --- /dev/null +++ b/lab08/03.cpp @@ -0,0 +1,128 @@ +#include +#include +#include +using namespace std; + +class Piece { +public: + int a, b, c, d; + Piece(int _a, int _b, int _c, int _d) { + a = _a; + b = _b; + c = _c; + d = _d; + } + void rot() { + int tmp = a; + a = b; + b = d; + d = c; + c = tmp; + } +}; + +void print(vector< vector >* v); + +void resolve(vector< vector >* v, int n, int a = 0, int b = 0) { + if(a >= n || b >= n) { + // solution found + cout<<"------------------------------------------------------------------------------------\n\n\n"; + print(v); + return; + } + + for(int i=0; i<4; i++) { + v->at(a)[b].rot(); + + // check if fits + if(a > 0) { + if(v->at(a)[b].a != v->at(a-1)[b].d) { + // doesn't fit to the part on its top + continue; + } + } + if(b > 0) { + if(v->at(a)[b].b != v->at(a)[b-1].c) { + // doesn't fit to the part on its left + continue; + } + } + + resolve(v, n, b == n-1 ? a+1 : a, b == n-1 ? 0 : b+1); + } +} + +int main(){ + cout<<"N = "; + int n; + cin>>n; + + vector< vector > v; + cout<<"Form:\n"; + cout<<"+---------+\n"; + cout<<"|\\ /|\n"; + cout<<"| \\ A / |\n"; + cout<<"| \\ / |\n"; + cout<<"| B |X| C |\n"; + cout<<"| / \\ |\n"; + cout<<"| / D \\ |\n"; + cout<<"|/ \\|\n"; + cout<<"+---------+\n"; + + for(int i=0; i row; + for(int j=0; j >* v) { + for(vector< vector >::iterator row = v->begin(); row < v->end(); row++) { + print_pattern("+---------+", row->size()); + print_pattern("|\\ /|", row->size()); + for(int i=0; isize(); i++) { + cout<<"| \\ "<at(i).a<<" / | "; + } + cout<<"\n"; + print_pattern("| \\ / |", row->size()); + for(int i=0; isize(); i++) { + cout<<"| "<at(i).b<<" |X| "<at(i).c<<" | "; + } + cout<<"\n"; + print_pattern("| / \\ |", row->size()); + for(int i=0; isize(); i++) { + cout<<"| / "<at(i).d<<" \\ | "; + } + cout<<"\n"; + print_pattern("|/ \\|", row->size()); + print_pattern("+---------+", row->size()); + cout<<"\n\n"; + } +}