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;
- using System.IO;
- namespace CasualOntario
- {
- class Program
- {
- static ConsoleKey keyToClose = ConsoleKey.Escape;
- static Random rnd = new Random();
- static bool ToClose()
- {
- return Console.ReadKey().Key == keyToClose;
- }
- // Ввод size массива с клавиатуры.
- static bool EnterArraySize(ref int arrSize)
- {
- Console.WriteLine("Введите кол-во элементов массива (Целое положительное число int)...");
- return (int.TryParse(Console.ReadLine(), out arrSize));
- }
- // Создание нового одномерного массива размерностью от 0 до 16.
- static int[] NewArrayGenerate(ref int countElem)
- {
- int[] arr = new int[rnd.Next(0, 16)];
- for (int i = 0; i < arr.Length; i++)
- arr[i] = rnd.Next(0, 1000);
- countElem += (arr.Length + 1) / 2;
- return arr;
- }
- // Создание корневого массива
- static int[][] FirstCernelArrayGenerate(ref int countElem)
- {
- int arrSize = 0;
- while (!EnterArraySize(ref arrSize))
- Console.WriteLine("Некорректный ввод данных, try еще раз...");
- int[][] cernelArr = new int[arrSize][];
- for (int i = 0; i < arrSize; i++)
- cernelArr[i] = NewArrayGenerate(ref countElem);
- return cernelArr;
- }
- static int[] SecondArrayGenerate(int countElem, int[][] firstArr)
- {
- int[] arr = new int[countElem];
- int ind = 0;
- for (int i = 0; i < firstArr.Length; i++)
- for (int j = 0; j < firstArr[i].Length; j++)
- if (j % 2 == 0)
- {
- arr[ind] = firstArr[i][j];
- ind++;
- }
- return arr;
- }
- // Вывод массива массивов.
- static void ShowFirstArray(int[][] arr)
- {
- Console.WriteLine("Массив A");
- for (int i = 0; i < arr.Length; i++)
- {
- Console.Write("{0} (size = {1}) : ", i + 1, arr[i].Length);
- for (int j = 0; j < arr[i].Length; j++)
- Console.Write(arr[i][j] + " ");
- Console.WriteLine();
- }
- }
- static void ShowSecondArray(int[] secondArr)
- {
- Console.WriteLine("Массив B");
- for (int i = 0; i < secondArr.Length; ++i)
- Console.Write(secondArr[i] + " ");
- }
- static void Main(string[] args)
- {
- do
- {
- int countElem = 0;
- int[][] cernelArray = FirstCernelArrayGenerate(ref countElem);
- ShowFirstArray(cernelArray);
- int[] secondArr = SecondArrayGenerate(countElem, cernelArray);
- ShowSecondArray(secondArr);
- Console.WriteLine("Чтобы закончить работу программы нажмите Escape...");
- } while (!ToClose());
- Console.WriteLine("Программа завершила работу...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement