Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleAppMathMem;
- class Program
- {
- private static readonly Random rand = new();
- public static void Main()
- {
- Table table = new(rand.Next(2, 50 + 1));
- Console.WriteLine($"Size:\t{table.Size}");
- Console.WriteLine(table);
- Console.WriteLine($"Answer A:\t{table.GetA()}");
- List<int> listB = table.GetB();
- Console.WriteLine($"Answer B:\t{string.Join(' ', listB.Count == 0 ? "None" : listB)}");
- Console.WriteLine($"Answer C:\t{table.GetC()}");
- }
- }
- public class Table
- {
- private readonly Random rand = new();
- private int[][] mass;
- private int size;
- public int Size
- {
- get { return size; }
- set
- {
- size = value;
- mass = new int[size][];
- for (int i = 0; i < size; i++)
- {
- mass[i] = new int[size];
- for (int j = 0; j < size; j++)
- {
- if (i == j)
- mass[i][j] = 0;
- else
- mass[i][j] = rand.Next(0, 2 + 1);
- }
- }
- }
- }
- public Table(int size) => Size = size;
- public int GetA()
- {
- int output = 0;
- for (int i = 0; i < size; i++)
- {
- if (mass[i].Count(num => num.Equals(0)) - 1
- < mass[i].Count(num => num.Equals(2)))
- {
- output++;
- }
- }
- return output;
- }
- public List<int> GetB()
- {
- List<int> output = new();
- for (int i = 0; i < size; i++)
- if (mass[i].Count(num => num.Equals(0)) == 1)
- output.Add(i + 1);
- return output;
- }
- public bool GetC()
- {
- int halfWin = (size + 1) / 2;
- for (int i = 0; i < size; i++)
- if (mass[i].Count(num => num.Equals(2)) >= halfWin)
- return true;
- return false;
- }
- public override string ToString()
- {
- string output = "";
- for (var i = 0; i < size; i++)
- {
- for (var j = 0; j < size; j++)
- output += $"{mass[i][j]} ";
- output += '\n';
- }
- return output;
- }
- }
Add Comment
Please, Sign In to add comment