fbinnzhivko

05.01 Wave Bits

Apr 21st, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int blurAmount = int.Parse(Console.ReadLine());
  8.         int[] size = Console.ReadLine().Split().Select(int.Parse).ToArray();
  9.  
  10.         double[,] matrix = new double[size[0], size[1]];
  11.  
  12.         for (int i = 0; i < matrix.GetLength(0); i++)
  13.         {
  14.             string[] nums = Console.ReadLine().Split();
  15.  
  16.             for (int j = 0; j < matrix.GetLength(1); j++)
  17.             {
  18.                 matrix[i, j] = double.Parse(nums[j]);
  19.             }
  20.         }
  21.         int[] targetCordinates = Console.ReadLine().Split().Select(int.Parse).ToArray();
  22.  
  23.         matrix[targetCordinates[0], targetCordinates[1]] += blurAmount;
  24.  
  25.         int row = matrix.GetLength(0);
  26.         int col = matrix.GetLength(1);
  27.  
  28.         if (targetCordinates[0] - 1 >= 0) { matrix[targetCordinates[0] - 1, targetCordinates[1]] += blurAmount; }
  29.         if (targetCordinates[0] + 1 < row) { matrix[targetCordinates[0] + 1, targetCordinates[1]] += blurAmount; }
  30.         if (targetCordinates[1] + 1 < col) { matrix[targetCordinates[0], targetCordinates[1] + 1] += blurAmount; }
  31.         if (targetCordinates[1] - 1 >= 0) { matrix[targetCordinates[0], targetCordinates[1] - 1] += blurAmount; }
  32.  
  33.         if (targetCordinates[0] - 1 >= 0 && targetCordinates[1] - 1 >= 0)
  34.         { matrix[targetCordinates[0] - 1, targetCordinates[1] - 1] += blurAmount; }
  35.  
  36.         if (targetCordinates[0] + 1 < row && targetCordinates[1] + 1 < col)
  37.         { matrix[targetCordinates[0] + 1, targetCordinates[1] + 1] += blurAmount; }
  38.  
  39.         if (targetCordinates[0] - 1 >= 0 && targetCordinates[1] + 1 < col)
  40.         { matrix[targetCordinates[0] - 1, targetCordinates[1] + 1] += blurAmount; }
  41.  
  42.         if (targetCordinates[0] + 1 < row && targetCordinates[1] - 1 >= 0)
  43.         { matrix[targetCordinates[0] + 1, targetCordinates[1] - 1] += blurAmount; }
  44.  
  45.         for (int i = 0; i < matrix.GetLength(0); i++)
  46.         {
  47.             for (int j = 0; j < matrix.GetLength(1); j++)
  48.             {
  49.                 Console.Write(matrix[i, j] + " ");
  50.             }
  51.             Console.WriteLine();
  52.         }
  53.     }
  54. }
Add Comment
Please, Sign In to add comment