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 FifthTask
- {
- public static int firstPossition;
- public static int secondPossition;
- public static int survivedWarriors = 0;
- public static bool firstFloor = false;
- public static int[,] matrix = new int[8, 8];
- static void Main()
- {
- int totalWarriors = 0;
- int finalResult = 0;
- for (int i = 0; i < 8; i++)
- {
- int tempNumber = int.Parse(Console.ReadLine());
- for (int k = 0; k < 8; k++)
- {
- int mask = 1 << k;
- int nAndMask = tempNumber & mask;
- int bit = nAndMask >> k;
- if (bit == 1)
- {
- totalWarriors++;
- }
- matrix[i, 7-k] = bit;
- }
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end")
- {
- break;
- }
- firstPossition = int.Parse(Console.ReadLine());
- secondPossition = int.Parse(Console.ReadLine());
- switch (command)
- {
- case "select": Select(firstPossition, secondPossition); break;
- case "kill": kill(firstPossition, secondPossition); break;
- case "move": move(firstPossition, secondPossition); break;
- default: break;
- }
- }
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- int tempNumber = 0;
- for (int k = 0; k < matrix.GetLength(1); k++)
- {
- if (matrix[i, k] == 1)
- {
- int p = 7-k;
- int mask = 1 << p;
- tempNumber = tempNumber | mask;
- survivedWarriors++;
- }
- }
- finalResult += tempNumber;
- }
- Console.WriteLine(totalWarriors);
- Console.WriteLine(survivedWarriors);
- Console.WriteLine(finalResult);
- }
- private static void move(int firstPossition, int secondPossition)
- {
- bool warriorOnLeft = false;
- bool warriorOnRight = false;
- if (firstPossition < 0 || firstPossition > 7 || secondPossition < 0 || secondPossition > 7)
- {
- return;
- }
- if (secondPossition != 0)
- {
- if (matrix[firstPossition, secondPossition - 1] == 1)
- {
- warriorOnLeft = true;
- }
- }
- if (secondPossition != 7)
- {
- if (matrix[firstPossition, secondPossition + 1] == 1)
- {
- warriorOnRight = true;
- }
- }
- if (warriorOnLeft || warriorOnRight || matrix[firstPossition, secondPossition] == 1)
- {
- firstFloor = false;
- return;
- }
- else
- {
- matrix[firstPossition, secondPossition] = 1;
- }
- firstFloor = false;
- }
- private static void kill(int firstPossition, int secondPossition)
- {
- bool warriorOnLeft = false;
- bool warriorOnRight = false;
- if (firstPossition < 0 || firstPossition > 7 || secondPossition < 0 || secondPossition > 7)
- {
- if (firstFloor)
- {
- survivedWarriors++;
- }
- return;
- }
- if (secondPossition != 0)
- {
- if (matrix[firstPossition, secondPossition - 1] == 1)
- {
- warriorOnLeft = true;
- }
- }
- if (secondPossition != 7)
- {
- if (matrix[firstPossition, secondPossition + 1] == 1)
- {
- warriorOnRight = true;
- }
- }
- if (warriorOnLeft && warriorOnRight)
- {
- matrix[firstPossition, secondPossition] = 0;
- }
- else if (warriorOnLeft && !warriorOnRight)
- {
- matrix[firstPossition, secondPossition] = 0;
- matrix[firstPossition, secondPossition - 1] = 0;
- }
- else if (!warriorOnLeft && warriorOnRight)
- {
- matrix[firstPossition, secondPossition] = 0;
- matrix[firstPossition, secondPossition + 1] = 0;
- }
- else if (!warriorOnLeft && !warriorOnRight)
- {
- matrix[firstPossition, secondPossition] = 1;
- }
- firstFloor = false;
- }
- private static void Select(int first ,int second)
- {
- matrix[first, second] = 0;
- if (first == 0 || first == 1)
- {
- firstFloor = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment