Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define LINT long long int
- #define ULINT unsigned long long int
- #define INF 99999999999
- using namespace std;
- template<typename tmp>
- void input(vector<tmp>& vc) {
- for (tmp& x : vc)
- cin >> x;
- }
- template<typename tmp>
- void output(vector<tmp>& vc, string endll = " ", string endd = "\n") {
- for (tmp& x : vc)
- cout << x << endll;
- cout << endd;
- }
- void fun(vector<vector<int> > &vc, int fx, int fy) {
- queue<pair<int, int> > q;
- q.push({fx, fy});
- while (!q.empty()) {
- pair<int, int> t = q.front();
- int x = t.first, y = t.second;
- q.pop();
- if (vc[x - 1][y] == 1) {
- vc[x - 1][y] = 3;
- q.push({x - 1, y});
- }
- if (vc[x + 1][y] == 1) {
- vc[x + 1][y] = 4;
- q.push({x + 1, y});
- }
- if (vc[x][y + 1] == 1) {
- vc[x][y + 1] = 5;
- q.push({x, y + 1});
- }
- if (vc[x][y - 1] == 1) {
- vc[x][y - 1] = 6;
- q.push({x, y - 1});
- }
- }
- }
- int main(){
- int n, m, x, y;
- cin >> n >> m;
- vector<vector<int> > vc(n, vector<int>(m, 0));
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < m; ++j) {
- char t;
- cin >> t;
- if (t == '.')
- vc[i][j] = 1;
- else
- if (t == 'S') {
- x = i;
- y = j;
- vc[i][j] = 2;
- }
- }
- fun(vc, x, y);
- for (auto x : vc) {
- for (auto y : x) {
- switch (y) {
- case 0:
- cout << '#';
- break;
- case 1:
- cout << '.';
- break;
- case 2:
- cout << 'S';
- break;
- case 3:
- cout << 'D';
- break;
- case 4:
- cout << 'U';
- break;
- case 5:
- cout << 'L';
- break;
- case 6:
- cout << 'R';
- break;
- }
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement