wym36

Untitled

Jul 23rd, 2025
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, m, q, x, y;
  9.     cin >> n >> m >> q >> x >> y;
  10.  
  11.     int a[105][105] = {};
  12.  
  13.     int dx[4] = {0, 1, 0, -1};
  14.     int dy[4] = {1, 0, -1, 0};
  15.  
  16.     int z = 0;
  17.     for(int i=1; i<=q; i++)
  18.     {
  19.         int t;
  20.         cin >> t;
  21.         if(t == 1)
  22.         {
  23.             x += dx[z];
  24.             y += dy[z];
  25.  
  26.         }
  27.         if(t == 2)
  28.         {
  29.             z += 1;
  30.             if(z == 4)
  31.             {
  32.                 z = 0;
  33.             }
  34.         }
  35.  
  36.         if(x < 0 || x >= n || y < 0 || y >= m)
  37.         {
  38.             x -= dx[z];
  39.             y -= dy[z];
  40.         }
  41.         else
  42.         {
  43.             a[x][y] = i;
  44.         }
  45.     }
  46.  
  47.     for(int i=0; i<n; i++)
  48.     {
  49.         for(int j=0; j<m; j++)
  50.             cout << a[i][j] << " ";
  51.         cout << "\n";
  52.     }
  53.  
  54.  
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment