Advertisement
braveheart1989

BlurFilter

Apr 20th, 2016
118
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. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.BlurFilter
  8. {
  9.     class BlurFilter
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long blurAmount = long.Parse(Console.ReadLine());
  14.             string[] input = Console.ReadLine().Split(' ');
  15.             long rows = long.Parse(input[0]);
  16.             long cols = long.Parse(input[1]);
  17.             long[,] matrix = new long[rows, cols];
  18.  
  19.             ReadMatrix(rows, cols, matrix);
  20.  
  21.             string[] target = Console.ReadLine().Split(' ');
  22.             long rowsBlur = long.Parse(target[0]);
  23.             long colsBlur = long.Parse(target[1]);
  24.  
  25.             //Console.WriteLine();
  26.  
  27.             long[,] newMatrix = new long[matrix.GetLength(0), matrix.GetLength(1)];
  28.  
  29.             for (int row = 0; row < matrix.GetLength(0); row++)
  30.             {
  31.                 for (int col = 0; col < matrix.GetLength(1); col++)
  32.                 {                    
  33.                     if ((row == rowsBlur && col == colsBlur) || (row == rowsBlur - 1 && col == colsBlur - 1)
  34.                         || (row == rowsBlur - 1 && col == colsBlur) || (row == rowsBlur - 1 && col == colsBlur + 1)
  35.                         || (row == rowsBlur && col == colsBlur - 1) || (row == rowsBlur && col == colsBlur + 1)
  36.                         || (row == rowsBlur + 1 && col == colsBlur - 1) || (row == rowsBlur + 1 && col == colsBlur)
  37.                         || (row == rowsBlur + 1 && col == colsBlur + 1))
  38.                     {
  39.                         newMatrix[row, col] = matrix[row, col] + blurAmount;
  40.                     }
  41.                     else
  42.                     {
  43.                         newMatrix[row, col] = matrix[row, col];
  44.                     }
  45.                 }
  46.             }
  47.  
  48.             PrintMatrix(matrix, newMatrix);
  49.         }
  50.  
  51.         static void ReadMatrix(long rows, long cols, long[,] matrix)
  52.         {
  53.             for (int row = 0; row < rows; row++)
  54.             {
  55.                 long[] cells = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
  56.  
  57.                 for (int col = 0; col < cols; col++)
  58.                 {
  59.                     matrix[row, col] = cells[col];
  60.                 }
  61.             }
  62.         }
  63.  
  64.         static void PrintMatrix(long[,] matrix, long[,] newMatrix)
  65.         {
  66.             for (int row = 0; row < matrix.GetLength(0); row++)
  67.             {
  68.                 for (int col = 0; col < matrix.GetLength(1); col++)
  69.                 {
  70.                     Console.Write(newMatrix[row, col] + " ");
  71.                 }
  72.                 Console.WriteLine();
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement