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;
- class BunkerBuster
- {
- static void Main(string[] args)
- {
- int[] size = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
- int rows = size[0];
- int cols = size[1];
- int[,] matrix = new int[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- int[] currentRow = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = currentRow[col];
- }
- }
- //input checked
- while (true)
- {
- string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- if (input[0] + " " + input[1] == "cease fire!")
- break;
- int bombRow = int.Parse(input[0]);
- int bombCol = int.Parse(input[1]);
- char symbol = char.Parse(input[2]);
- int damage = (int)symbol;
- int halfDamage = (int)Math.Ceiling(((decimal)damage)/2);
- //bombardment
- try
- {
- matrix[bombRow, bombCol] -= damage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow-1, bombCol-1] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow - 1, bombCol] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow - 1, bombCol + 1] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow, bombCol-1] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow, bombCol + 1] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow + 1, bombCol - 1] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow + 1, bombCol] -= halfDamage;
- }
- catch (Exception) { }
- try
- {
- matrix[bombRow + 1, bombCol + 1] -= halfDamage;
- }
- catch (Exception) { }
- }
- int destroyedCells = 0;
- //checks for destroyed cells
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (matrix[row,col] <= 0)
- destroyedCells++;
- }
- }
- decimal damageDone = ((decimal)destroyedCells / (rows * cols))*100;
- //PrintMatrix(matrix);
- Console.WriteLine("Destroyed bunkers: {0}", destroyedCells);
- Console.WriteLine("Damage done: {0:F1} %", damageDone);
- }
- public static void PrintMatrix(int[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment