Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace teyn_superior
- {
- class Nigga
- {
- public static Random rng = new Random();
- public static int IntReader()
- {
- int num = (int)default;
- bool success = (bool)default;
- while (!success)
- {
- if (int.TryParse(Console.ReadLine(), out num) && num > 0)
- {
- success = true;
- }
- else
- {
- Console.WriteLine("Неправильный ввод, введите число снова");
- }
- }
- return num;
- }
- public static int[][] RandomMatrixGenerator(int m, int n)
- {
- int[][] array = new int[m][];
- for (int i = 0; i < m; i++)
- {
- array[i] = new int[n];
- for (int g = 0; g < n; g++)
- {
- array[i][g] = rng.Next(-784, 785);
- }
- }
- return array;
- }
- public static void LargestRowDetector(int[][] array)
- {
- Console.WriteLine();
- int max = (int)default;
- int counter = (int)default;
- int[] sum = new int[array.Length];
- for (int i = 0; i < sum.Length; i++)
- sum[i] = 0;
- for (int i = 0; i < array.Length; i++)
- {
- for (int g = 0; g < array[i].Length; g++)
- {
- sum[i] += array[i][g];
- }
- }
- for (int i = 0; i < sum.Length; i++)
- {
- if (sum[i] >= max)
- {
- max = sum[i];
- counter = i;
- }
- }
- Console.WriteLine("Номер строки, сумма элементов которой максимальна: " + counter);
- Console.WriteLine("Сумма элементов этой строки: " + max);
- }
- public static void ArrayToConsole(int[][] array)
- {
- Console.WriteLine();
- for (int i = 0; i < array.Length; i++)
- {
- for (int g = 0; g < array[i].Length; g++)
- {
- Console.Write(array[i][g] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- class Program
- {
- private static void Main(string[] args)
- {
- bool end = (bool)default;
- while (!end)
- {
- Console.WriteLine("Введите N");
- int n = Nigga.IntReader();
- Console.WriteLine("Введите M");
- int m = Nigga.IntReader();
- int[][] array = Nigga.RandomMatrixGenerator(m, n);
- Nigga.ArrayToConsole(array);
- Nigga.LargestRowDetector(array);
- Console.WriteLine("Запустить решение сначала? Введите 8, чтобы запустить, 1, чтобы завершить работу программы.");
- if (Nigga.IntReader() == 8)
- {
- end = false;
- }
- else
- {
- if (Nigga.IntReader() == 1)
- {
- end = true;
- }
- else Console.WriteLine("Неправильный ввод, повторите еще раз");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement