Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_Projects
- {
- class Program
- {
- static readonly int imageWidthAndHeight = 4;
- static void Main(string[] args)
- {
- int[,] image = new int [,] {
- {1,2,3,4},
- {2,3,5,7},
- {4,7,9,9},
- {9,5,3,2}
- };
- char[,] solution = Solve(image);
- for (int i = 0; i < imageWidthAndHeight; i++)
- {
- for (int j = 0; j < imageWidthAndHeight; j++)
- {
- Console.Write(solution[i, j]);
- if (j == imageWidthAndHeight - 1)
- Console.WriteLine();
- }
- }
- }
- static char[,] Solve(int[,] image)
- {
- char[,] arrows = new char[imageWidthAndHeight, imageWidthAndHeight];
- int currentValue, maxValue;
- int leftValue, rightValue, bottomValue, topValue;
- for (int row = 0; row < imageWidthAndHeight; row++)
- {
- for (int col = 0; col < imageWidthAndHeight; col++)
- {
- currentValue = image[row, col];
- leftValue = rightValue = topValue = bottomValue = -1; //lower than 0
- if (col != 0)
- leftValue = image[row, col - 1];
- if (col != imageWidthAndHeight - 1)
- rightValue = image[row, col + 1];
- if (row != imageWidthAndHeight - 1)
- bottomValue = image[row + 1, col];
- if (row != 0)
- topValue = image[row - 1, col];
- arrows[row, col] = 'o';
- maxValue = currentValue;
- if(currentValue < leftValue)
- {
- arrows[row, col] = '<';
- maxValue = leftValue;
- }
- if(topValue > maxValue)
- {
- arrows[row, col] = '^';
- maxValue = topValue;
- }
- if(rightValue > maxValue)
- {
- arrows[row, col] = '>';
- maxValue = rightValue;
- }
- if (bottomValue > maxValue)
- {
- arrows[row, col] = 'v';
- }
- }
- }
- return arrows;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement