Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Compare(int[,] array1, int[,] array2)
- {
- int counter1 = 0;
- for (int i = 0; i < array1.GetLength(dimension: 0); i++)
- {
- for (int j = 0; j < array1.GetLength(dimension: 1); j++)
- {
- if (array1[i,j] < 0)
- counter1++;
- }
- }
- int counter2 = 0;
- for (int i = 0; i < array2.GetLength(dimension: 0); i++)
- {
- for (int j = 0; j < array2.GetLength(dimension: 1); j++)
- {
- if (array2[i,j] < 0)
- counter2++;
- }
- }
- Console.ForegroundColor = ConsoleColor.Green;
- if (counter1 > counter2)
- {
- Console.WriteLine("Matrix 1 = {0}, Matrix 2 = {1}", counter1, counter2);
- Console.WriteLine("В матрице 2 меньше отриц. чисел, чем в матрице 1\n");
- DeleteStroke(array2);
- }
- else if (counter1 < counter2)
- {
- Console.WriteLine("Matrix 1 = {0}, Matrix 2 = {1}", counter1, counter2);
- Console.WriteLine("В матрице 1 меньше отриц. чисел, чем в матрице 2\n");
- DeleteStroke(array1);
- }
- else
- {
- Console.WriteLine("У матриц одинаковое кол-во отрицательных чисел");
- throw new NotImplementedException("Матрицы одинаковые");
- }
- }
- static void DeleteStroke(int[,] array)
- {
- Console.ResetColor();
- int Max = Int32.MinValue;
- int MaxIndex = -1;
- for (int i = 0; i < array.GetLength(0); i++)
- {
- int StrokeSum = 0;
- for (int j = 0; j < array.GetLength(1); j++)
- {
- StrokeSum += array[i, j];
- }
- Console.WriteLine("Сумма элементов строки {0} = {1}",i+1,StrokeSum);
- if (StrokeSum > Max)
- {
- Max = StrokeSum;
- MaxIndex = i;
- }
- }
- Console.WriteLine();
- for (int j = 0; j < array.GetLength(1); j++)
- array[MaxIndex, j] = -100;
- for (int i = 0; i < array.GetLength(dimension: 0); i++)
- {
- for (int j = 0; j < array.GetLength(dimension: 1); j++)
- {
- if (array[i,j] != -100)
- Console.Write("{0,3}", array[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void CreateMatrix(ref int[,] a, Random r)
- {
- Console.WriteLine("\nМатрица");
- for (int i = 0; i < a.GetLength(dimension: 0); i++)
- {
- for (int j = 0; j < a.GetLength(dimension: 1); j++)
- {
- a[i, j] = r.Next(-5, 6);
- Console.Write("{0,3}", a[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- int[,] Array1 = new int[3,3];
- int[,] Array2 = new int[4,3];
- Random r = new Random(9951967);
- CreateMatrix(ref Array1, r);
- CreateMatrix(ref Array2, r);
- Console.WriteLine("Press any key to continue...");
- Console.ReadLine();
- Compare(Array1, Array2);
- Console.Read();
- }
- }
- }
Add Comment
Please, Sign In to add comment