Advertisement
Guest User

Untitled

a guest
May 10th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2.  
  3. namespace C_Projects
  4. {
  5.     class Program
  6.     {
  7.         static readonly int imageWidthAndHeight = 4;
  8.  
  9.         static void Main(string[] args)
  10.         {
  11.             int[,] image = new int [,] {
  12.                 {1,2,3,4},
  13.                 {2,3,5,7},
  14.                 {4,7,9,9},
  15.                 {9,5,3,2}
  16.             };
  17.  
  18.             char[,] solution = Solve(image);
  19.  
  20.             for (int i = 0; i < imageWidthAndHeight; i++)
  21.             {
  22.                
  23.                 for (int j = 0; j < imageWidthAndHeight; j++)
  24.                 {
  25.                     Console.Write(solution[i, j]);
  26.                     if (j == imageWidthAndHeight - 1)
  27.                         Console.WriteLine();
  28.                 }
  29.             }
  30.         }
  31.  
  32.         static char[,] Solve(int[,] image)
  33.         {
  34.             char[,] arrows = new char[imageWidthAndHeight, imageWidthAndHeight];
  35.             int currentValue, maxValue;
  36.             int leftValue, rightValue, bottomValue, topValue;
  37.  
  38.             for (int row = 0; row < imageWidthAndHeight; row++)
  39.             {
  40.                 for (int col = 0; col < imageWidthAndHeight; col++)
  41.                 {
  42.                     currentValue = image[row, col];
  43.                     leftValue = rightValue = topValue = bottomValue = -1; //lower than 0
  44.                    
  45.                     if (col != 0)
  46.                         leftValue = image[row, col - 1];                  
  47.                    
  48.                     if (col != imageWidthAndHeight - 1)
  49.                         rightValue = image[row, col + 1];
  50.  
  51.                     if (row != imageWidthAndHeight - 1)
  52.                         bottomValue = image[row + 1, col];
  53.  
  54.                     if (row != 0)
  55.                         topValue = image[row - 1, col];
  56.  
  57.                     arrows[row, col] = 'o';
  58.                     maxValue = currentValue;
  59.                    
  60.                     if(currentValue < leftValue)
  61.                     {
  62.                         arrows[row, col] = '<';
  63.                         maxValue = leftValue;
  64.                     }
  65.  
  66.                     if(topValue > maxValue)
  67.                     {
  68.                         arrows[row, col] = '^';
  69.                         maxValue = topValue;
  70.                     }
  71.  
  72.                     if(rightValue > maxValue)
  73.                     {
  74.                         arrows[row, col] = '>';
  75.                         maxValue = rightValue;
  76.                     }
  77.  
  78.                     if (bottomValue > maxValue)
  79.                     {
  80.                         arrows[row, col] = 'v';
  81.                     }  
  82.                 }
  83.             }
  84.  
  85.             return arrows;
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement