mirror of
https://github.com/KhasanovAMdev/ISTU_TEST_LR1.git
synced 2026-02-03 03:49:36 +04:00
Код задачи
This commit is contained in:
10
LR1/AppTesting/AppTesting.csproj
Normal file
10
LR1/AppTesting/AppTesting.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
48
LR1/AppTesting/Program.cs
Normal file
48
LR1/AppTesting/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
internal class Program
|
||||
{
|
||||
private static float[] inputArray = {
|
||||
1.5f, -2.4f, 3.1f, 0.5f, 12.7f, -8.2f, 4.4f, 9.0f, 01511.0f
|
||||
};
|
||||
private static void Main()
|
||||
{
|
||||
Console.WriteLine($"Массив с входными данными: [{string.Join("; ", inputArray)}]");
|
||||
|
||||
var outputData = ArrayProc(inputArray);
|
||||
|
||||
Console.WriteLine($"Массив с выходными данными: [{string.Join("; ", outputData ?? Array.Empty<float>())}]");
|
||||
}
|
||||
|
||||
|
||||
private static float[]? ArrayProc(float[] inputData)
|
||||
{
|
||||
float[] outputArray;
|
||||
int pairs = 0;
|
||||
int n = inputData.Length - 1;
|
||||
for (int i = 0; i <= n / 2; i++)
|
||||
{
|
||||
if (i + 8 <= n) pairs++;
|
||||
}
|
||||
|
||||
if (pairs == 0)
|
||||
{
|
||||
Console.WriteLine("Размер массива не соответствует условию");
|
||||
return null;
|
||||
}
|
||||
|
||||
outputArray = new float[pairs];
|
||||
|
||||
for (int i = 8, j = 0; j < outputArray.Length; j++, i++)
|
||||
{
|
||||
outputArray[j] = inputData[i] * inputData[i - 8];
|
||||
}
|
||||
|
||||
if (outputArray.Length % 2 != 0)
|
||||
{
|
||||
int centralIdx = outputArray.Length / 2;
|
||||
float centralItem = outputArray[centralIdx];
|
||||
outputArray[centralIdx] = centralItem * centralItem;
|
||||
}
|
||||
return outputArray;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user