Другие языки программирования и технологии

С клавиатуры вводится n – длина ступенчатого массива.

Сформировать и вывести на экран ступенчатый массив,
элементы которого формируются случайно в диапазоне [-3;3].
А длина каждого следующего ступенчатого массива в два раза
больше предыдущего. К примеру, длина первого массива
равняется одному, второго двум, а третьего уже четырем
элементам и т. д. Найти произведение минимальных элементов
каждого массива, входящих в массив массивов.
Парочка классов:

public class BaseStepArray< T >
{
public delegate int NextSizeDel(int CurrentSize);
public delegate T FillDel(int LineNo, int ElementNo);
protected T[][] InternalArray = null;
public BaseStepArray(int FirstStepSize, int LineCount, NextSizeDel NextSizeRule)
{
InternalArray = new T[LineCount][];
for (int i = 0; i < LineCount; i++)
{
InternalArray[i] = new T[FirstStepSize];
FirstStepSize = NextSizeRule(FirstStepSize);
}
}

public override string ToString()
{
string Result = string.Empty;
for (int i = 0; i < InternalArray.Length; i++)
{
for (int j = 0; j < InternalArray[i].Length; j++)
Result += InternalArray[i][j].ToString() + " ";
Result += Environment.NewLine;
}
return Result;
}

public void Fill(FillDel FillRule)
{
for (int i = 0; i < InternalArray.Length; i++)
for (int j = 0; j < InternalArray[i].Length; j++)
InternalArray[i][j] = FillRule(i, j);
}

public T[] this[int Index] { get => InternalArray[Index]; }

}

public class MyLineArray: BaseStepArray
{
public MyLineArray(int FirstStepSize, int LineCount) : base (FirstStepSize, LineCount, x => x*2)
{
Random r = new Random(DateTime.Now.Millisecond);
Fill((x, y) => r.Next(-3, 3));
}

public int[] GetMinLineValues()
{
int[] Result = new int[InternalArray.Length];
for (int i = 0; i < InternalArray.Length; i++)
Result[i] = InternalArray[i].Min();
return Result;
}

}

Сама программа - короче некуда:

static void Main(string[] args)
{
MyLineArray a = new MyLineArray(1, 5);
Console.WriteLine(a);
Console.WriteLine(a.GetMinLineValues().Aggregate(1, (x, y) => x * y));
Console.ReadKey();
}
Сергей Гордин
Сергей Гордин
76 025
Лучший ответ
Сергей Гордин public class MyLineArray: BaseStepArray должно быть public class MyLineArray: BaseStepArray < int > - "Ответы" пожрали скобки. Разрешай редактировать ответы.

Похожие вопросы