Advertisement
CyberN00b

Untitled

Sep 7th, 2022
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define LINT long long int
  3. #define ULINT unsigned long long int
  4. #define INF 99999999999
  5.  
  6. using namespace std;
  7.  
  8. template<typename tmp>
  9. void input(vector<tmp>& vc) {
  10.     for (tmp& x : vc)
  11.         cin >> x;
  12. }
  13. template<typename tmp>
  14. void output(vector<tmp>& vc, string endll = " ", string endd = "\n") {
  15.     for (tmp& x : vc)
  16.         cout << x << endll;
  17.     cout << endd;
  18. }
  19.  
  20. void fun(vector<vector<int> > &vc, int fx, int fy) {
  21.     queue<pair<int, int> > q;
  22.     q.push({fx, fy});
  23.     while (!q.empty()) {
  24.         pair<int, int> t = q.front();
  25.         int x = t.first, y = t.second;
  26.         q.pop();
  27.         if (vc[x - 1][y] == 1) {
  28.             vc[x - 1][y] = 3;
  29.             q.push({x - 1, y});
  30.         }
  31.         if (vc[x + 1][y] == 1) {
  32.             vc[x + 1][y] = 4;
  33.             q.push({x + 1, y});
  34.         }
  35.         if (vc[x][y + 1] == 1) {
  36.             vc[x][y + 1] = 5;
  37.             q.push({x, y + 1});
  38.         }
  39.         if (vc[x][y - 1] == 1) {
  40.             vc[x][y - 1] = 6;
  41.             q.push({x, y - 1});
  42.         }
  43.     }
  44. }
  45.  
  46. int main(){
  47.     int n, m, x, y;
  48.     cin >> n >> m;
  49.     vector<vector<int> > vc(n, vector<int>(m, 0));
  50.     for (int i = 0; i < n; ++i)
  51.         for (int j = 0; j < m; ++j) {
  52.             char t;
  53.             cin >> t;
  54.             if (t == '.')
  55.                 vc[i][j] = 1;
  56.             else
  57.                 if (t == 'S') {
  58.                     x = i;
  59.                     y = j;
  60.                     vc[i][j] = 2;
  61.                 }
  62.         }
  63.     fun(vc, x, y);
  64.     for (auto x : vc) {
  65.         for (auto y : x) {
  66.             switch (y) {
  67.                 case 0:
  68.                 cout << '#';
  69.                 break;
  70.                 case 1:
  71.                 cout << '.';
  72.                 break;
  73.                 case 2:
  74.                 cout << 'S';
  75.                 break;
  76.                 case 3:
  77.                 cout << 'D';
  78.                 break;
  79.                 case 4:
  80.                 cout << 'U';
  81.                 break;
  82.                 case 5:
  83.                 cout << 'L';
  84.                 break;
  85.                 case 6:
  86.                 cout << 'R';
  87.                 break;
  88.             }
  89.         }
  90.         cout << endl;
  91.     }
  92.  
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement