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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| int array_1[][4] = { {1, 1, 1, 1}, {3, 3, 3, 3}, {5, 5, 5, 7}, }; int array_2[][5] = { {2, 2, 2, 2, 2}, {4, 4, 4, 4, 4}, {6, 6, 6, 6, 6}, {8, 8, 8, 8, 8}, }; enum array_dir { en_left, en_right, en_top, en_down, };
vector<vector<int> > new_array;
void init_new_array() { int _1_x = sizeof(array_1) / sizeof(array_1[0]); int _1_y = sizeof(array_1[0]) / sizeof(array_1[0][0]); int _2_x = sizeof(array_2) / sizeof(array_2[0]); int _2_y = sizeof(array_2[0]) / sizeof(array_2[0][0]); int max_x = _1_x + _2_x + 1; int max_y = _1_y + _2_y + 1; for (x..) { vector<int> line; for (y..) { line.push_back(0); } new_array.push_back(line); } }
void insert_top_left(vector<vector<int> >& _array, int _x, int _y) { for (x = 0; x < _x; ++x) { for (y = 0; y < _y; ++y) { new_array[x][y] = _array[x][y]; } } }
void insert_down_right(vector<vector<int> >& _array, int _x, int _y, int _pos_x, int _pos_y) { for (x = _pos_x; x < _x + _pos_x; ++x) { for (y = _pos_y; y < _y + _pos_y; ++y) { new_array[x][y] = _array[x - _pos_x][y - _pos_y]; } } }
void mv_top_down(int _x, int _y) { for (int x = _x - 1; x >= 0; --x) { for (int y = 0; y < _y; ++y) { new_array[x + 1][y] = new_array[x][y]; } } for (int y = 0; y < _y; ++y) new_array[0][y] = 0; }
void mv_top_right(int _x, int _y) { for (int x = 0; x < _x; ++x) { for (int y = _y - 1; y >= 0; --y) { new_array[x][y + 1] = new_array[x][y]; } } for (int x = 0; x < _x; ++x) { new_array[x][0] = 0; } }
void mv_down_top(int _x, int _y, int _max_x, int _max_y) { for (int x = _x; x < _max_x; ++x) { for (int y = _y; y < _max_y; ++y) { new_array[x - 1][y] = new_array[x][y]; } } for (int y = _y; y < _max_y; ++y) new_array[_max_x - 1][y] = 0; }
void mv_down_left(int _x, int _y, int _max_x, int _max_y) { for (int x = _x; x < _max_x; ++x) { for (int y = _y; y < _max_y; ++y) { new_array[x][y - 1] = new_array[x][y]; } } for (int x = _x; x < _max_x; ++x) new_array[x][_max_y - 1] = 0; }
|