Untitled
unknown
plain_text
3 years ago
3.1 kB
5
Indexable
using System;
class Program
{
static void Main(string[] args)
{
int[,] matrix = new int[8, 8];
Random rand = new Random();
// Populate the matrix with random 0s and 1s
for (int row = 0; row < 8; row++)
{
for (int col = 0; col < 8; col++)
{
matrix[row, col] = rand.Next(0, 2);
}
}
// Display the matrix
Console.WriteLine("Matrica:");
for (int row = 0; row < 8; row++)
{
for (int col = 0; col < 8; col++)
{
Console.Write(matrix[row, col] + " ");
}
Console.WriteLine();
}
// Check for attacking queens
for (int row = 0; row < 8; row++)
{
for (int col = 0; col < 8; col++)
{
if (matrix[row, col] == 1)
{
// Check row
for (int i = 0; i < 8; i++)
{
if (i != col && matrix[row, i] == 1)
{
Console.WriteLine("Napadaju se!");
return;
}
}
// Check column
for (int i = 0; i < 8; i++)
{
if (i != row && matrix[i, col] == 1)
{
Console.WriteLine("Napadaju se!");
return;
}
}
// Check main diagonal
for (int i = 1; i < 8; i++)
{
if (row + i < 8 && col + i < 8 && matrix[row + i, col + i] == 1)
{
Console.WriteLine("They are attacking each other.");
return;
}
if (row - i >= 0 && col - i >= 0 && matrix[row - i, col - i] == 1)
{
Console.WriteLine("They are attacking each other.");
return;
}
}
// Check side diagonal
for (int i = 1; i < 8; i++)
{
if (row + i < 8 && col - i >= 0 && matrix[row + i, col - i] == 1)
{
Console.WriteLine("They are attacking each other.");
return;
}
if (row - i >= 0 && col + i < 8 && matrix[row - i, col + i] == 1)
{
Console.WriteLine("They are attacking each other.");
return;
}
}
}
}
}
Console.WriteLine("Nijedna kraljica ne napada drugu!");
}
}Editor is loading...