Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Crossroads
- {
- static void Main()
- {
- int sizeOfBoard = int.Parse(Console.ReadLine());
- int[,] matrix = new int[sizeOfBoard, sizeOfBoard];
- string input = Console.ReadLine();
- int crossroads = 0;
- while (input != "end")
- {
- string[] predefinedCrossroad = input.Split(' ');
- int line = int.Parse(predefinedCrossroad[0]);
- int position = int.Parse(predefinedCrossroad[1]);
- if (line == 0 || line == sizeOfBoard - 1 || position == 0 || position == sizeOfBoard - 1)
- {
- crossroads++; // predefined crossroad which will not be detected in the scan later.
- }
- int col = position;
- int row = line;
- while (col >= 0 && row <= sizeOfBoard - 1) // filling the matrix to bottom right
- {
- matrix[row, col] = 1;
- row++;
- col--;
- }
- col = position;
- row = line;
- while (col <= sizeOfBoard - 1 && row >= 0) // filling the matrix to upper left
- {
- matrix[row, col] = 1;
- row--;
- col++;
- }
- col = position;
- row = line;
- while (col >= 0 && row >= 0) // filling the matrix to upper right
- {
- matrix[row, col] = 1;
- row--;
- col--;
- }
- col = position;
- row = line;
- while (col <= sizeOfBoard - 1 && row <= sizeOfBoard - 1) // filling to bottom left
- {
- matrix[row, col] = 1;
- row++;
- col++;
- }
- input = Console.ReadLine();
- }
- string binary = "";
- long integer = 0;
- for (int row = 0; row <= sizeOfBoard - 1; row++)
- {
- for (int col = sizeOfBoard - 1; col >= 0; col--)
- {
- binary += matrix[row, col]; // getting the string representation of the binary number
- if ((row > 0 && row < sizeOfBoard - 1) && (col > 0 && col < sizeOfBoard - 1))
- {
- if (matrix[row, col] == 1 && matrix[row + 1, col + 1] == 1 && matrix[row - 1, col + 1] == 1 && matrix[row + 1, col - 1] == 1 && matrix[row - 1, col - 1] == 1)
- {
- crossroads++; // checking for a crossroad
- }
- }
- }
- Console.WriteLine(integer = Convert.ToInt64(binary, 2)); // binary to integer
- binary = ""; // getting the binary again to default value because otherwise all numbers will stack.
- }
- Console.WriteLine(crossroads);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment