Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int horizon{ 4 };
- const int vertical{ 4 };
- int arr[vertical][horizon]{ {1, 15, 3, 4}, {5, 0, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 2} };
- // std::cout << "enter direction of shift 1-right, 2-left, 3-up, 4-down: ";
- // std::cin >> dir;
- for (int y{ 0 }; y < vertical; ++y)
- {
- int copy;
- for (int x{ 0 }; x < horizon; ++x)
- {
- int shift_h{ 0 };
- int shift_v{ 0 };
- /* if (arr[n][i+1] == 0) // right
- {
- shift_v = 0;
- shift_h = 1 ;
- }*/
- if (arr[y][x - 1] == 0) // left
- {
- shift_h = -1;
- copy = arr[y][x];
- arr[y][x] = 0;
- arr[y][x + shift_h] = copy;
- ++x;
- }
- }
- }
- for (int y{ 0 }; y < vertical; ++y)
- {
- for (int x{ 0 }; x < horizon; ++x)
- {
- std::cout << arr[y][x] << '\t';
- }
- std::cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement