botgob

Untitled

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