Advertisement
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 _05_BitTower
- {
- class Program
- {
- static void Main(string[] args)
- {
- //input and fill the matrix
- string[] numbers = new string[8];
- for (int i = 0; i < 8; i++)
- {
- int input = int.Parse(Console.ReadLine());
- numbers[i] = Convert.ToString(input, 2).PadLeft(8, '0');
- }
- char[,] field = new char[8, 8];
- for (int row = 7; row >= 0; row--)
- {
- for (int col = 0; col < 8; col++)
- {
- field[row, col] = numbers[row][col];
- }
- }
- int enteredKnights = 0;
- for (int row = 0; row < 8; row++)
- {
- for (int col = 0; col < 8; col++)
- {
- if (field[row, col] == '1')
- {
- enteredKnights++;
- }
- }
- }
- int survivors = 0;
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "select")
- {
- int selectFloor = int.Parse(Console.ReadLine());
- int selectPosition = int.Parse(Console.ReadLine());
- field[selectFloor, selectPosition] = '0';
- }
- else if (command == "kill")
- {
- int killFloor = int.Parse(Console.ReadLine());
- int killPosition = int.Parse(Console.ReadLine());
- if (killPosition == 0)
- {
- if (field[killFloor, killPosition] == '1')
- {
- }
- else if (field[killFloor, killPosition + 1] == '1')
- {
- field[killFloor, killPosition + 1] = '0';
- }
- }
- else if (killPosition == 7)
- {
- if (field[killFloor, killPosition] == '1')
- {
- }
- else if (field[killFloor, killPosition - 1] == '1')
- {
- field[killFloor, killPosition - 1] = '0';
- }
- }
- else if ((killPosition < 0 || killPosition > 7) && killFloor <= 1)
- {
- survivors++;
- }
- else if (killPosition > 0 && killPosition < 7)
- {
- if (field[killFloor, killPosition] == '1')
- {
- }
- else if (field[killFloor, killPosition - 1] == '1' && field[killFloor, killPosition + 1] == '0')
- {
- field[killFloor, killPosition - 1] = '0';
- }
- else if (field[killFloor, killPosition + 1] == '1' && field[killFloor, killPosition - 1] == '0')
- {
- field[killFloor, killPosition + 1] = '0';
- }
- else if ((field[killFloor, killPosition + 1] == '1') && (field[killFloor, killPosition + 1] == '1'))
- {
- }
- else if (field[killFloor, killPosition] == '0')
- {
- field[killFloor, killPosition] = '1';
- }
- }
- }
- else if (command == "move")
- {
- int moveFloor = int.Parse(Console.ReadLine());
- int movePosition = int.Parse(Console.ReadLine());
- if (movePosition == 0 && movePosition + 1 == '0')
- {
- field[moveFloor, movePosition] = '1';
- }
- else if (movePosition == 7 && movePosition - 1 == '0')
- {
- field[moveFloor, movePosition] = '1';
- }
- else if ((movePosition < 0 || movePosition > 7) && moveFloor <= 1)
- {
- survivors++;
- }
- }
- else if (command == "end")
- {
- break;
- }
- }
- for (int row = 0; row < 8; row++)
- {
- for (int col = 0; col < 8; col++)
- {
- if (field[row, col] == '1')
- {
- survivors++;
- }
- }
- }
- string[] newNumbers = new string[8];
- for (int row = 0; row < 8; row++)
- {
- for (int col = 0; col < 8; col++)
- {
- newNumbers[row] += field[row, col];
- }
- }
- int sumOfAllInts = 0;
- for (int i = 0; i < 8; i++)
- {
- int currentNumber = Convert.ToInt32(newNumbers[i], 2);
- sumOfAllInts += currentNumber;
- }
- Console.WriteLine(enteredKnights);
- Console.WriteLine(survivors);
- Console.WriteLine(sumOfAllInts);
- //printing
- //for (int row = 0; row < 8; row++)
- //{
- // for (int col = 0; col < 8; col++)
- // {
- // Console.Write(field[row, col]);
- // }
- // Console.WriteLine();
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement