Advertisement
den4ik2003

Untitled

Oct 29th, 2023
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5.   int m, n;
  6.   std::cin >> m >> n;
  7.   std::vector<std::vector<int>> a(n, std::vector<int>(m));
  8.  
  9.   int count = 1;
  10.   for (int shift_j = 0; shift_j < m; ++shift_j) {
  11.     int i = 0;
  12.     int j = shift_j;
  13.     while (i < n && j >= 0) {
  14.       a[i][j] = count;
  15.       ++count;
  16.       ++i;
  17.       --j;
  18.     }
  19.   }
  20.   for (int shift_i = 1; shift_i < n; ++shift_i) {
  21.     int i = shift_i;
  22.     int j = m - 1;
  23.     while (i < n && j >= 0) {
  24.       a[i][j] = count;
  25.       ++count;
  26.       ++i;
  27.       --j;
  28.     }
  29.   }
  30.  
  31.   for (int i = 0; i < n; ++i) {
  32.     for (int j = 0; j < m; ++j) {
  33.       std::cout << a[i][j] << " ";
  34.     }
  35.     std::cout << '\n';
  36.   }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement