Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace SandBox
- {
- public class Program
- {
- static void Main(string[] args)
- {
- Queue<Tuple<int, int>> q = new Queue<Tuple<int, int>>();
- string d = Console.ReadLine();
- int n = Convert.ToInt32(d.Split(' ')[0]);
- int m = Convert.ToInt32(d.Split(' ')[1]);
- List<List<char>> lab = new List<List<char>>(n);
- for (int i = 0; i < n; i++)
- {
- lab.Add(new List<char>(m));
- for (int j = 0; j < m; j++)
- {
- lab[i].Add('_');
- }
- }
- for (int i = 0; i < n; i++)
- {
- string col = Console.ReadLine();
- for (int j = 0; j < m; j++)
- {
- lab[i][j] = col[j];
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (lab[i][j] == 'S')
- {
- q.Enqueue(new Tuple<int, int>(i,j));
- }
- }
- }
- while (q.Count > 0)
- {
- Tuple<int, int> tmp = q.Dequeue();
- if (tmp.Item1 - 1 >= 0 && lab[tmp.Item1 - 1][tmp.Item2] == '.')
- {
- q.Enqueue(new Tuple<int, int>(tmp.Item1 - 1, tmp.Item2));
- lab[tmp.Item1 - 1][tmp.Item2] = 'U';
- }
- if (tmp.Item1 + 1 < n && lab[tmp.Item1 + 1][tmp.Item2] == '.')
- {
- q.Enqueue(new Tuple<int, int>(tmp.Item1 + 1, tmp.Item2));
- lab[tmp.Item1 + 1][tmp.Item2] = 'D';
- }
- if (tmp.Item2 - 1 >= 0 && lab[tmp.Item1][tmp.Item2 - 1] == '.')
- {
- q.Enqueue(new Tuple<int, int>(tmp.Item1, tmp.Item2 - 1));
- lab[tmp.Item1][tmp.Item2 - 1] = 'L';
- }
- if (tmp.Item2 + 1 >= 0 && lab[tmp.Item1][tmp.Item2 + 1] == '.')
- {
- q.Enqueue(new Tuple<int, int>(tmp.Item1, tmp.Item2 + 1));
- lab[tmp.Item1][tmp.Item2 + 1] = 'R';
- }
- }
- foreach (var s in lab)
- {
- foreach (var s1 in s)
- {
- Console.Write(s1);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement