botgob

eldberget

Nov 20th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Eldberget
  8. {
  9.     public class Node
  10.     {
  11.         public int x;
  12.         public int y;
  13.         public int ln;
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             Node p = new Node();
  21.             p.x = 0;
  22.             p.y = 0;
  23.             p.ln = 0;
  24.             string indata = Console.ReadLine();
  25.             string[] indataArray = indata.Split();
  26.             int x = int.Parse(indataArray[0]);
  27.             int y = int.Parse(indataArray[1]);
  28.             int k = int.Parse(indataArray[2]);
  29.             String[,] rutnät = new String[x, y];
  30.             Boolean[,] redanV = new bool[x, y];
  31.             for (int i = 0; i < y; i++)
  32.             {
  33.                 indata = Console.ReadLine();
  34.                 for (int j = 0; j < x; j++)
  35.                 {
  36.                     rutnät[j, i] = indata[j].ToString();
  37.                 }
  38.             }
  39.             Queue<Node>= new Queue<Node>();
  40.             kö.Enqueue(p);
  41.             while (.Count > 0)
  42.             {
  43.                 Node cur =.Dequeue();
  44.                 if (cur.x + 1 <= x && rutnät[cur.x + 1, cur.y] != "#" && redanV[cur.x + 1, cur.y] == false)
  45.                 {
  46.                     Node next = new Node();
  47.                     next.x = cur.x + 1;
  48.                     next.y = cur.y;
  49.                     next.ln = cur.ln + 1;
  50.                     kö.Enqueue(next);
  51.                     redanV[cur.x + 1, cur.y] = true;
  52.                 }
  53.                 if (cur.y + 1 <= y && rutnät[cur.x, cur.y + 1] != "#" && redanV[cur.x, cur.y] == false)
  54.                 {
  55.                     Node next = new Node();
  56.                     next.x = cur.x;
  57.                     next.y = cur.y + 1;
  58.                     next.ln = cur.ln + 1;
  59.                     kö.Enqueue(next);
  60.                     redanV[cur.x, cur.y + 1] = true;
  61.                 }
  62.                 if (cur.y - 1 <= 0 && rutnät[cur.x, cur.y - 1] != "#" && redanV[cur.x, cur.y - 1] == false)
  63.                 {
  64.                     Node next = new Node();
  65.                     next.x = cur.x;
  66.                     next.y = cur.y - 1;
  67.                     next.ln = cur.ln + 1;
  68.                     kö.Enqueue(next);
  69.                     redanV[cur.x, cur.y - 1] = true;
  70.                 }
  71.                 if (cur.x - 1 <= 0 && rutnät[cur.x - 1, cur.y] != "#" && redanV[cur.x - 1, cur.y] == false)
  72.                 {
  73.                     Node next = new Node();
  74.                     next.x = cur.x - 1;
  75.                     next.y = cur.y;
  76.                     next.ln = cur.ln + 1;
  77.                     kö.Enqueue(next);
  78.                     redanV[cur.x - 1, cur.y] = true;
  79.                 }
  80.             }
  81.  
  82.            
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment