Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- int main() {
- int m, n;
- std::cin >> m >> n;
- std::vector<std::vector<int>> a(n, std::vector<int>(m));
- int count = 1;
- for (int shift_j = 0; shift_j < m; ++shift_j) {
- int i = 0;
- int j = shift_j;
- while (i < n && j >= 0) {
- a[i][j] = count;
- ++count;
- ++i;
- --j;
- }
- }
- for (int shift_i = 1; shift_i < n; ++shift_i) {
- int i = shift_i;
- int j = m - 1;
- while (i < n && j >= 0) {
- a[i][j] = count;
- ++count;
- ++i;
- --j;
- }
- }
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- std::cout << a[i][j] << " ";
- }
- std::cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement