Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _01.BunkerBuster
- {
- class BunkerBuster
- {
- //static long counter;
- static long[,] ReadMatrix(long rows, long cols, long[,] matrix)
- {
- for (int row = 0; row < rows; row++)
- {
- long[] cells = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions
- .RemoveEmptyEntries)
- .Select(long.Parse)
- .ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = cells[col];
- }
- }
- return matrix;
- }
- static void BombMatrix(long targetRow, long targetCol, char power, long[,] matrix, long[,] newMatrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- bool isTarget = IsTarget(targetRow, targetCol, row, col);
- if (isTarget)
- {
- if (newMatrix[row, col] < 0)
- {
- continue;
- }
- else
- {
- newMatrix[row, col]
- = matrix[row, col] - (long)Math.Ceiling((double)power / 2);
- //counter = CellsDestroyed(newMatrix, counter, row, col);
- }
- }
- if (row == targetRow && col == targetCol)
- {
- if (newMatrix[row, col] < 0)
- {
- continue;
- }
- else
- {
- newMatrix[row, col] = matrix[row, col] - power;
- //counter = CellsDestroyed(newMatrix, counter, row, col);
- }
- }
- else if (!isTarget)
- {
- newMatrix[row, col] = matrix[row, col];
- }
- }
- }
- }
- static int CountDestroyedCells(long[,] newMatrix)
- {
- int counter = 0;
- for (int row = 0; row < newMatrix.GetLength(0); row++)
- {
- for (int col = 0; col < newMatrix.GetLength(1); col++)
- {
- if (newMatrix[row, col] <= 0)
- {
- counter++;
- }
- }
- }
- return counter;
- }
- static bool IsTarget(long targetRow, long targetCol, long row, long col)
- {
- return (row == targetRow - 1 && col == targetCol - 1)
- || (row == targetRow - 1 && col == targetCol)
- || (row == targetRow - 1 && col == targetCol + 1)
- || (row == targetRow && col == targetCol - 1)
- || (row == targetRow && col == targetCol + 1)
- || (row == targetRow + 1 && col == targetCol - 1)
- || (row == targetRow + 1 && col == targetCol)
- || (row == targetRow + 1 && col == targetCol + 1);
- }
- static void Main(string[] args)
- {
- long[] dimension = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
- long rows = dimension[0];
- long cols = dimension[1];
- long[,] matrix = new long[rows, cols];
- long matrixSize = rows * cols;
- ReadMatrix(rows, cols, matrix);
- string[] coordinates = Console.ReadLine().ToLower().Split(' ');
- long targetRow = long.Parse(coordinates[0]);
- long targetCol = long.Parse(coordinates[1]);
- char power = char.Parse(coordinates[2]);
- long[,] newMatrix = new long[matrix.GetLength(0), matrix.GetLength(1)];
- while (!coordinates[0].Contains("cease"))
- {
- BombMatrix(targetRow, targetCol, power, matrix, newMatrix);
- //PrintMatrix(matrix, newMatrix);
- targetRow = long.Parse(coordinates[0]);
- targetCol = long.Parse(coordinates[1]);
- power = char.Parse(coordinates[2]);
- coordinates = Console.ReadLine().ToLower().Split(' ');
- matrix = newMatrix;
- }
- int counter = CountDestroyedCells(newMatrix);
- double result = Math.Round(counter / (double)(matrixSize) * 100, 1);
- Console.WriteLine("Destroyed bunkers: {0}", counter);
- Console.WriteLine("Damage done: {0:F1} %", result);
- //PrintMatrix(matrix, newMatrix);
- }
- static void PrintMatrix(long[,] matrix, long[,] newMatrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write("{0,10}", newMatrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement