Advertisement
Guest User

Blur Filter

a guest
Jun 2nd, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 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 BlurFilter
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int blur_amount = int.Parse(Console.ReadLine());
  14.             int[] d = Array.ConvertAll(Console.ReadLine().Split(' '), s => int.Parse(s));
  15.             var matrix = new int[d[0], d[1]];
  16.  
  17.             for (var i = 0; i < d[0]; i++)
  18.             {
  19.                 var line = Console.ReadLine();
  20.                 var spl = line.Split(' ');
  21.                 if (spl.Length != d[1]) {
  22.                     throw new FormatException();
  23.                 }
  24.                 for (var j = 0; j < d[1]; j++)
  25.                     matrix[i, j] = int.Parse(spl[j]);
  26.             }
  27.  
  28.             var coords = Console.ReadLine().Split(' ');
  29.             if (coords.Length != 2) {
  30.                 throw new FormatException();
  31.             }
  32.  
  33.             matrix = DoTheMath(matrix, coords, blur_amount);
  34.             GetStatus(matrix);
  35.         }
  36.  
  37.         public static int[,] DoTheMath(int[,] matrix, string[] coords, int blur_amount)
  38.         {
  39.             for (int row = 0; row < matrix.GetLength(0); row++)
  40.             {
  41.                 for (int col = 0; col < matrix.GetLength(1); col++)
  42.                 {
  43.                     if (row == int.Parse(coords[0]) && col == int.Parse(coords[1]))
  44.                     {
  45.                         matrix[row, col] += blur_amount;
  46.                         matrix[row, col - 1] += blur_amount;
  47.                         matrix[row - 1, col - 1] += blur_amount;
  48.                         matrix[row - 1, col] += blur_amount;
  49.                         matrix[row - 1, col + 1] += blur_amount;
  50.                         matrix[row, col + 1] += blur_amount;
  51.                         matrix[row + 1, col + 1] += blur_amount;
  52.                         matrix[row + 1, col] += blur_amount;
  53.                         matrix[row + 1, col - 1] += blur_amount;
  54.                     }
  55.  
  56.                 }
  57.             }
  58.             return matrix;
  59.         }
  60.  
  61.         public static void GetStatus(int[,] matrix) {
  62.  
  63.             for (int i = 0; i < matrix.GetLength(0); i++)
  64.             {
  65.                 for (int a = 0; a < matrix.GetLength(1); a++)
  66.                 {
  67.                     Console.Write("{0} ", matrix[i, a]);
  68.                 }
  69.                 Console.WriteLine();
  70.             }
  71.  
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement