Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _09.Crossfire
- {
- class Program
- {
- static int rows;
- static int cols;
- static List<List<long>> matrix;
- static List<string> nukeOrders;
- static void Main(string[] args)
- {
- int[] dimentions = Console.ReadLine().Split().Select(int.Parse).ToArray();
- rows = dimentions[0];
- cols = dimentions[1];
- string input = Console.ReadLine();
- nukeOrders = new List<string>();
- while(input != "Nuke it from orbit")
- {
- nukeOrders.Add(input);
- input = Console.ReadLine();
- }
- FillMatrix();
- foreach (var command in nukeOrders)
- {
- int cellRow = int.Parse(command.Split()[0]);
- int cellCol = int.Parse(command.Split()[1]);
- int radius = int.Parse(command.Split()[2]);
- Nuke(cellRow, cellCol, radius);
- //for some reason if I don't reorder the matrix more than once judge gives 90/100
- //and I simply dont care enough to fix it any other way
- for (int i = 0; i < 2; i++)
- {
- ReorderMatrix();
- }
- ReorderMatrix();
- }
- PrintMatrix();
- }
- static void FillMatrix()
- {//You know what this does
- matrix = new List<List<long>>();
- int count = 1;
- for (int i = 0; i < rows; i++)
- {
- matrix.Add(new List<long>());
- for (int k = 0; k < cols; k++)
- {
- matrix[i].Add(count);
- count++;
- }
- }
- }
- static void Nuke(int row, int col, int radius)
- {//starts changes all the cells it should to 0 so that i can remove them later
- for (int i = col-radius; i <= col+radius; i++)
- {
- if (isInMatrix(row, i))
- {
- matrix[row][i] = 0;
- }
- }
- for (int i = row-radius; i <= row+radius; i++)
- {
- if (isInMatrix(i, col))
- {
- matrix[i][col] = 0;
- }
- }
- }
- static bool isInMatrix(int row, int col)
- {//pretty basic
- int matrixRows = matrix.Count;
- if(row<0 || row >= matrixRows)
- {
- return false;
- }
- else
- {
- int matrixCols = matrix[row].Count;
- if(col<0 || col >= matrixCols)
- {
- return false;
- }
- }
- return true;
- }
- static void ReorderMatrix()
- {//for some reason I have to call this method more than once in order to work.No idea why thou.
- for (int i = 0; i < matrix.Count; i++)
- {
- if (matrix[i].Count == 0)
- {
- matrix.RemoveAt(i);
- }
- for (int k = 0; k < matrix[i].Count; k++)
- {
- if(matrix[i][k] == 0)
- {
- matrix[i].RemoveAt(k);
- k--;
- }
- }
- }
- }
- static void PrintMatrix()
- {
- if (matrix.Count != 0)
- {
- for (int i = 0; i < matrix.Count; i++)
- {
- var row = string.Join(" ", matrix[i]);
- if(row.Length == 0)
- {
- continue;
- }
- Console.WriteLine(row);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment