fbinnzhivko

05.00 Multiply Targeted Cell

Apr 26th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. class TheMatrix
  4. {
  5.     static void Main()
  6.     {
  7.         //Matrix Dimensions
  8.         long[] matrixDimensions = Console.ReadLine().Split().Select(long.Parse).ToArray();
  9.         long rows = matrixDimensions[0];
  10.         long cols = matrixDimensions[1];
  11.  
  12.         //Creating and Filling our new matrix
  13.         long[,] matrix = new long[rows, cols];
  14.  
  15.         for (long i = 0; i < rows; i++)
  16.         {
  17.             long[] row = Console.ReadLine().Split().Select(long.Parse).ToArray();
  18.  
  19.             for (long j = 0; j < cols; j++)
  20.             {
  21.                 matrix[i, j] = row[j];
  22.             }
  23.         }
  24.         //Special Point
  25.         long[] blurCoordinates = Console.ReadLine().Split().Select(long.Parse).ToArray();
  26.  
  27.         long point = matrix[blurCoordinates[0], blurCoordinates[1]];
  28.         long sum = 0;
  29.  
  30.         long startRow = blurCoordinates[0] - 1 >= 0 ? blurCoordinates[0] - 1 : 0;
  31.         long startCol = blurCoordinates[1] - 1 >= 0 ? blurCoordinates[1] - 1 : 0;
  32.         long endRow = blurCoordinates[0] + 1 < rows ? blurCoordinates[0] + 1 : rows - 1;
  33.         long endCol = blurCoordinates[1] + 1 < cols ? blurCoordinates[1] + 1 : cols - 1;
  34.  
  35.         for (long i = startRow; i <= endRow; i++)
  36.         {
  37.             for (long j = startCol; j <= endCol; j++)
  38.             {
  39.                 sum = sum + matrix[i, j];
  40.                 matrix[i, j] = matrix[i, j] * point;
  41.                 matrix[blurCoordinates[0], blurCoordinates[1]] /= point;
  42.  
  43.             }
  44.         }
  45.         matrix[blurCoordinates[0], blurCoordinates[1]] = point * sum;
  46.  
  47.         PrintMatrix(matrix);
  48.     }
  49.  
  50.     static void PrintMatrix(long[,] matrix)
  51.     {
  52.         for (long i = 0; i < matrix.GetLength(0); i++)
  53.         {
  54.             for (long j = 0; j < matrix.GetLength(1); j++)
  55.             {
  56.                 Console.Write(matrix[i, j] + " ");
  57.             }
  58.             Console.WriteLine();
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment