Advertisement
AUTOMATIC1111

Untitled

May 10th, 2019
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2.  
  3. namespace darkest
  4. {
  5.     class Program
  6.     {
  7.         static int[,] pixels = new int[,] {
  8.             { 1,2,3,4 },
  9.             { 2,3,5,7 },
  10.             { 4,7,9,9 },
  11.             { 9,5,3,2 }
  12.         };
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             process(pixels);
  17.         }
  18.  
  19.         private static void process(int[,] pixels)
  20.         {
  21.             int w = pixels.GetLength(0);
  22.             int h = pixels.GetLength(1);
  23.             int[,] darkestNearby = new int[w, h];
  24.             char[,] result = new char[w, h];
  25.  
  26.             for (int y = 0; y < h; y++)
  27.             {
  28.                 int a = pixels[y, 0];
  29.                 for (int x = 0; x < w - 1; x++)
  30.                 {
  31.                     int b = pixels[y, x + 1];
  32.  
  33.                     if (a < b)
  34.                     {
  35.                         darkestNearby[y, x] = b;
  36.                         result[y, x] = '>';
  37.                     }
  38.                     else if (a > b)
  39.                     {
  40.                         darkestNearby[y, x + 1] = a;
  41.                         result[y, x + 1] = '<';
  42.                     }
  43.  
  44.                     a = b;
  45.                 }
  46.             }
  47.  
  48.             for (int x = 0; x < w; x++)
  49.             {
  50.                 int a = pixels[0, x];
  51.                 for (int y = 0; y < h - 1; y++)
  52.                 {
  53.                     int b = pixels[y + 1, x];
  54.  
  55.                     if (a < b)
  56.                     {
  57.                         if (darkestNearby[y, x] < b)
  58.                         {
  59.                             result[y, x] = 'v';
  60.                         }
  61.                     }
  62.                     else if (a > b)
  63.                     {
  64.                         if (darkestNearby[y + 1, x] < a)
  65.                         {
  66.                             result[y + 1, x] = '^';
  67.                         }
  68.                     }
  69.  
  70.                     a = b;
  71.                 }
  72.             }
  73.  
  74.             for (int x = 0; x < w; x++)
  75.             {
  76.                 for (int y = 0; y < h; y++)
  77.                 {
  78.                     char c = result[x, y];
  79.                     Console.Write(c == '\0' ? 'o' : c);
  80.                 }
  81.  
  82.                 Console.WriteLine();
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement