Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace Warhead
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] matrix = new int[16, 16];
- for (int i = 0; i < 16; i++)
- {
- string input = Console.ReadLine();
- char[] lineChars = input.ToCharArray();
- for (int ch = 0; ch < 16; ch++)
- {
- matrix[i, ch] = int.Parse(lineChars[ch].ToString());
- }
- }
- bool isArmed = true;
- while (isArmed)
- {
- string input = Console.ReadLine();
- switch (input)
- {
- case "hover":
- {
- int line = int.Parse(Console.ReadLine());
- int cell = int.Parse(Console.ReadLine());
- Console.WriteLine(Hover(line, cell, matrix));
- }
- break;
- case "operate":
- {
- int line = int.Parse(Console.ReadLine());
- int cell = int.Parse(Console.ReadLine());
- string result = Operate(line, cell, matrix);
- if (result != string.Empty)
- {
- isArmed = false;
- Console.WriteLine(result);
- }
- }
- break;
- case "cut":
- {
- isArmed = false;
- string wireColor = Console.ReadLine();
- if (wireColor == "left")
- {
- wireColor = "red";
- }
- if (wireColor == "right")
- {
- wireColor = "blue";
- }
- Console.WriteLine(CutWire(matrix, wireColor));
- }
- break;
- }
- }
- }
- private static string Hover(int line, int cell, int[,] matrix)
- {
- string result = "-";
- if (matrix[line, cell] == 1)
- {
- result = "*";
- }
- return result;
- }
- private static string Operate(int line, int cell, int[,] matrix)
- {
- string result = string.Empty;
- if (matrix[line, cell] == 1)
- {
- StringBuilder builder = new StringBuilder();
- builder.AppendLine("missed");
- builder.AppendLine(CountCapacitors(matrix, 0, 15, 0, 15).ToString());
- builder.Append("BOOM");
- result = builder.ToString();
- }
- else if (CheckIsCapacitor(matrix, line, cell))
- {
- matrix[line - 1, cell - 1] = 0;
- matrix[line - 1, cell] = 0;
- matrix[line - 1, cell + 1] = 0;
- matrix[line + 1, cell - 1] = 0;
- matrix[line + 1, cell] = 0;
- matrix[line + 1, cell + 1] = 0;
- matrix[line, cell - 1] = 0;
- matrix[line, cell + 1] = 0;
- }
- return result;
- }
- private static int CountCapacitors(int[,] matrix, int startLine,
- int endLine, int startCell, int endCell)
- {
- int count = 0;
- for (int line = startLine + 1; line < endLine; line++)
- {
- for (int cell = startCell + 1; cell < endCell; cell++)
- {
- if (CheckIsCapacitor(matrix, line, cell))
- {
- count++;
- }
- }
- }
- return count;
- }
- private static bool CheckIsCapacitor(int[,] matrix, int line, int cell)
- {
- try
- {
- return matrix[line - 1, cell - 1] == 1 && matrix[line + 1, cell + 1] == 1 &&
- matrix[line - 1, cell] == 1 && matrix[line + 1, cell] == 1 &&
- matrix[line - 1, cell + 1] == 1 && matrix[line + 1, cell - 1] == 1 &&
- matrix[line, cell - 1] == 1 && matrix[line, cell + 1] == 1;
- }
- catch
- {
- return false;
- }
- }
- private static string CutWire(int[,] matrix, string wireColor)
- {
- StringBuilder builder = new StringBuilder();
- int redCapacitors = CountCapacitors(matrix, 0, 15, 0, 8);
- int blueCapacitors = CountCapacitors(matrix, 0, 15, 7, 15);
- switch (wireColor)
- {
- case "red":
- {
- if (redCapacitors != 0)
- {
- builder.AppendLine(redCapacitors.ToString());
- builder.Append("BOOM");
- }
- else
- {
- builder.AppendLine(blueCapacitors.ToString());
- builder.Append("disarmed");
- }
- }
- break;
- case "blue":
- {
- if (blueCapacitors != 0)
- {
- builder.AppendLine(blueCapacitors.ToString());
- builder.Append("BOOM");
- }
- else
- {
- builder.AppendLine(redCapacitors.ToString());
- builder.Append("disarmed");
- }
- }
- break;
- }
- return builder.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement