Advertisement
simeon3000

Crossfire

Jan 27th, 2018
10,564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P09.Crossfire
  6. {
  7.     class Crossfire
  8.     {
  9.         static void Main()
  10.         {
  11.             int[] matrixSizes = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int rows = matrixSizes[0];
  13.             int cols = matrixSizes[1];
  14.  
  15.             var mainList = new List<List<int>>();
  16.             for (int r = 0; r < rows; r++)
  17.             {
  18.                 var rowList = new List<int>();
  19.                 for (int c = 0; c < cols; c++)
  20.                 {
  21.                     rowList.Add(r * cols + c + 1);
  22.                 }
  23.  
  24.                 mainList.Add(rowList);
  25.             }
  26.  
  27.             string command;
  28.             while ((command = Console.ReadLine()) != "Nuke it from orbit")
  29.             {
  30.                 int[] commandArgs = command.Split().Select(int.Parse).ToArray();
  31.                 int shotRow = commandArgs[0];
  32.                 int shotCol = commandArgs[1];
  33.                 int radius = commandArgs[2];
  34.  
  35.                 for (int r = 0; r < mainList.Count; r++)
  36.                 {
  37.                     for (int c = 0; c < mainList[r].Count; c++)
  38.                     {
  39.                         if ((r == shotRow && Math.Abs(c - shotCol) <= radius) ||
  40.                             (c == shotCol && Math.Abs(r - shotRow) <= radius))
  41.                         {
  42.                             mainList[r][c] = 0;
  43.                         }
  44.                     }
  45.                 }
  46.  
  47.                 for (int r = 0; r < mainList.Count; r++)
  48.                 {
  49.                     mainList[r].RemoveAll(x => x == 0);
  50.                     if (mainList[r].Count == 0)
  51.                     {
  52.                         mainList.RemoveAt(r);
  53.                         r--;
  54.                     }
  55.                 }              
  56.             }        
  57.  
  58.             for (int r = 0; r < mainList.Count; r++)
  59.             {              
  60.                 Console.WriteLine(string.Join(" ", mainList[r]));
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement