daily pastebin goal
41%
SHARE
TWEET

Crossfire

mausha Jan 29th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program
  6. {
  7.     public static void Main()
  8.     {
  9.         var sizes = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  10.         var r = sizes[0];
  11.         var c = sizes[1];
  12.  
  13.         var matrix = new List<List<int>>();
  14.         FillTheMatrixIn(r, c, matrix);
  15.  
  16.         string input;
  17.         while ((input = Console.ReadLine()) != "Nuke it from orbit")
  18.         {
  19.             var arg = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  20.             var hitRow = arg[0];
  21.             var hitCol = arg[1];
  22.             var radius = arg[2];
  23.             VerticalHitting(r, matrix, hitRow, hitCol, radius);
  24.             HorizontalHitting(matrix, hitRow, hitCol, radius);
  25.         }
  26.  
  27.         for (int rowIndex = 0; rowIndex < r; rowIndex++)
  28.         {
  29.             Console.WriteLine(string.Join(" ", matrix[rowIndex]));
  30.         }
  31.     }
  32.  
  33.     private static void HorizontalHitting(List<List<int>> matrix, int hitRow, int hitCol, int radius)
  34.     {
  35.         var length = radius * 2 + 1;
  36.         var start = hitCol - radius;
  37.         if (start < 0)
  38.         {
  39.             start = 0;
  40.         }
  41.         if (start + length >= matrix[hitRow].Count)
  42.         {
  43.             length -= start + length - matrix[hitRow].Count;
  44.         }
  45.  
  46.         matrix[hitRow].RemoveRange(start, length);
  47.     }
  48.  
  49.     private static void VerticalHitting(int r, List<List<int>> matrix, int hitRow, int hitCol, int radius)
  50.     {
  51.         for (int k = radius; k > 0; k--)
  52.         {
  53.             if (matrix[hitRow - k].Count >= hitCol)
  54.             {
  55.                 if (hitRow - k >= 0 && hitCol < matrix[hitRow - k].Count)
  56.                 {
  57.                     matrix[hitRow - k].RemoveAt(hitCol);
  58.                 }
  59.                 if (hitRow + k < matrix.Count && hitCol < matrix[hitRow + k].Count)
  60.                 {
  61.                     matrix[hitRow + k].RemoveAt(hitCol);
  62.                 }
  63.             }
  64.         }
  65.     }
  66.  
  67.     private static void FillTheMatrixIn(int r, int c, List<List<int>> matrix)
  68.     {
  69.         var number = 1;
  70.         for (int i = 0; i < r; i++)
  71.         {
  72.             matrix.Add(new List<int>());
  73.             for (int j = 0; j < c; j++)
  74.             {
  75.                 matrix[i].Add(j + number);
  76.             }
  77.  
  78.             number += c;
  79.         }
  80.     }
  81. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top