Advertisement
anilak

Neurons

Jun 26th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2.  
  3. class Neurons
  4. {
  5.     static void FillNeurons()
  6.     {
  7.         for (byte r = 0; r < 32; r++)
  8.         {
  9.             for(byte c = 0; c < 32; c++)
  10.             {
  11.                 if (grid[r, c] == 1 && !isOutside[r, c])
  12.                 {
  13.                     grid[r, c] = 0;
  14.                 }
  15.                 else if(grid[r, c] == 0 && !isOutside[r, c])
  16.                 {
  17.                     grid[r, c] = 1;
  18.                 }
  19.             }
  20.         }
  21.     }
  22.  
  23.     static void PrintGrid(byte limit)
  24.     {
  25.         for (byte r = 0; r < limit; r++)
  26.         {
  27.             uint result = 0;  
  28.             for(sbyte c = 31; c >= 0; c--)
  29.             {
  30.                 result += grid[r, c] * (uint)Math.Pow(2, c);
  31.             }
  32.             Console.WriteLine(result);
  33.         }
  34.     }
  35.  
  36.     static void FindOutsideArea(byte r, byte c)
  37.     {
  38.         if (r >= 32 || r < 0 || c >= 32 || c < 0)
  39.         {
  40.             return;
  41.         }
  42.         if (grid[r, c] == 1)
  43.         {
  44.             return;
  45.         }
  46.         if (isOutside[r, c] == true)
  47.         {
  48.             return;
  49.         }
  50.         isOutside[r, c] = true;
  51.         FindOutsideArea((byte)(r + 1), c);
  52.         FindOutsideArea(r, (byte)(c + 1));
  53.         FindOutsideArea((byte)(r - 1), c);
  54.         FindOutsideArea(r, (byte)(c - 1));
  55.     }
  56.  
  57.     static byte [,] grid = new byte [32,32];
  58.     static bool [,] isOutside = new bool[32,32];
  59.  
  60.     static void Main()
  61.     {
  62.         bool isValid = true;
  63.         byte counter = 0;
  64.         for (; ; counter++)
  65.         {
  66.             uint line;
  67.             isValid = uint.TryParse(Console.ReadLine(), out line);
  68.             if (!isValid)
  69.             {
  70.                 break;
  71.             }
  72.             for (byte j = 0; j < 32; j++)
  73.             {
  74.                 grid[counter, j] = (byte)((line >> j) & 1);
  75.             }
  76.         }
  77.         FindOutsideArea(0, 0);
  78.         FindOutsideArea((byte)(counter - 1), 0);
  79.         FindOutsideArea(0, (byte)31);
  80.         FindOutsideArea((byte)(counter - 1), (byte)31);
  81.         FillNeurons();
  82.         PrintGrid(counter);
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement