Advertisement
teyn_superior

Untitled

Nov 5th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace teyn_superior
  8. {
  9.     class Nigga
  10.     {
  11.         public static Random rng = new Random();
  12.  
  13.         public static int IntReader()
  14.         {
  15.             int num = (int)default;
  16.             bool success = (bool)default;
  17.             while (!success)
  18.             {
  19.                 if (int.TryParse(Console.ReadLine(), out num) && num > 0)
  20.                 {
  21.                     success = true;
  22.                 }
  23.                 else
  24.                 {
  25.                     Console.WriteLine("Неправильный ввод, введите число снова");
  26.                 }
  27.             }
  28.             return num;
  29.         }
  30.  
  31.         public static int[][] RandomMatrixGenerator(int m, int n)
  32.         {
  33.             int[][] array = new int[m][];
  34.             for (int i = 0; i < m; i++)
  35.             {
  36.                 array[i] = new int[n];
  37.                 for (int g = 0; g < n; g++)
  38.                 {
  39.                     array[i][g] = rng.Next(-784, 785);
  40.                 }
  41.             }
  42.             return array;
  43.         }
  44.  
  45.         public static void LargestRowDetector(int[][] array)
  46.         {
  47.             Console.WriteLine();
  48.             int max = (int)default;
  49.             int counter = (int)default;
  50.             int[] sum = new int[array.Length];
  51.             for (int i = 0; i < sum.Length; i++)
  52.                 sum[i] = 0;
  53.             for (int i = 0; i < array.Length; i++)
  54.             {
  55.                 for (int g = 0; g < array[i].Length; g++)
  56.                 {
  57.                     sum[i] += array[i][g];
  58.                 }
  59.             }
  60.             for (int i = 0; i < sum.Length; i++)
  61.             {
  62.                 if (sum[i] >= max)
  63.                 {
  64.                     max = sum[i];
  65.                     counter = i;
  66.                 }
  67.             }
  68.             Console.WriteLine("Номер строки, сумма элементов которой максимальна: " + counter);
  69.             Console.WriteLine("Сумма элементов этой строки: " + max);
  70.         }
  71.         public static void ArrayToConsole(int[][] array)
  72.         {
  73.             Console.WriteLine();
  74.             for (int i = 0; i < array.Length; i++)
  75.             {
  76.                 for (int g = 0; g < array[i].Length; g++)
  77.                 {
  78.                     Console.Write(array[i][g] + " ");
  79.                 }
  80.                 Console.WriteLine();
  81.             }
  82.         }
  83.     }
  84.  
  85.     class Program
  86.     {
  87.         private static void Main(string[] args)
  88.         {
  89.             bool end = (bool)default;
  90.             while (!end)
  91.             {
  92.                 Console.WriteLine("Введите N");
  93.                 int n = Nigga.IntReader();
  94.                 Console.WriteLine("Введите M");
  95.                 int m = Nigga.IntReader();
  96.  
  97.                 int[][] array = Nigga.RandomMatrixGenerator(m, n);
  98.                 Nigga.ArrayToConsole(array);
  99.                 Nigga.LargestRowDetector(array);
  100.  
  101.                 Console.WriteLine("Запустить решение сначала? Введите 8, чтобы запустить, 1, чтобы завершить работу программы.");
  102.                 if (Nigga.IntReader() == 8)
  103.                 {
  104.                     end = false;
  105.                 }
  106.                 else
  107.                 {
  108.                     if (Nigga.IntReader() == 1)
  109.                     {
  110.                         end = true;
  111.                     }
  112.                     else Console.WriteLine("Неправильный ввод, повторите еще раз");
  113.                 }
  114.             }
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement