Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Task5
- {
- static void Main()
- {
- int y = 0;
- bool hit = false;
- int flight = 0;
- int killedPigs = 0;
- int result = 0;
- int direction = -1;
- int[,] matrix = new int[8, 16];
- string input = "";
- for (byte x = 0; x < 8; x++)
- {
- input = Convert.ToString(int.Parse(Console.ReadLine()), 2).PadLeft(16, '0');
- for (int a = 0; a < 16; a++)
- {
- matrix[x, a] = int.Parse(Convert.ToString(input[a]));
- }
- }
- for (int i = 7; i >= 0; i--)
- {
- hit = false;
- for (int Y = 0; Y < 8; Y++)
- {
- if (matrix[Y,i] == 1)
- {
- matrix[Y, i] = 0;
- direction = -1;
- killedPigs = 0;
- flight = 0;
- int h = i;
- y = Y;
- while (h < 16)
- {
- if (y + direction > 7)
- {
- break;
- }
- flight++;
- if (y + direction > 7 || y + direction < 0)
- {
- direction = direction * -1;
- }
- h++;
- y = y + direction;
- if (y > 7 || y < 0 || h > 15 || h < 0)
- {
- continue;
- }
- if (h > 7)
- {
- if (matrix[y, h] == 1)
- {
- hit = true;
- for (int z = y - 1; z < y + 2; z++)
- {
- for (int k = h - 1; k < h + 2; k++)
- {
- if (z > 7 || z < 0 || k > 15 || k < 0)
- {
- continue;
- }
- if (matrix[z, k] == 1)
- {
- killedPigs++;
- matrix[z, k] = 0;
- }
- }
- }
- }
- }
- if (hit)
- {
- break;
- }
- }
- }
- if (hit)
- {
- result = result + (flight * killedPigs);
- break;
- }
- }
- }
- int check = 0;
- string win = "Yes";
- for (int i = 0; i < 8; i++)
- {
- for (int z = 0; z < 16; z++)
- {
- check = check + matrix[i, z];
- }
- }
- if (check > 0)
- {
- win = "No";
- }
- Console.WriteLine(result + " " + win);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement