This commit is contained in:
Akim 2024-11-19 15:55:29 +04:00
parent 8b5e913241
commit 37a50eafaa
4 changed files with 528 additions and 0 deletions

31
lab13.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35303.130
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab13", "lab13\lab13.vcxproj", "{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Debug|x64.ActiveCfg = Debug|x64
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Debug|x64.Build.0 = Debug|x64
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Debug|x86.ActiveCfg = Debug|Win32
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Debug|x86.Build.0 = Debug|Win32
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Release|x64.ActiveCfg = Release|x64
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Release|x64.Build.0 = Release|x64
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Release|x86.ActiveCfg = Release|Win32
{FE10DFB9-9083-48DE-81B1-CC1FC4EA111E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D619E66-F5E3-4887-A4A1-8E4719716F50}
EndGlobalSection
EndGlobal

340
lab13/FileName.c Normal file
View File

@ -0,0 +1,340 @@
#include <stdio.h>
#include <Windows.h>
#define NUM_ELEMENTS 20
int arr[NUM_ELEMENTS];
int arrHelp[NUM_ELEMENTS];
int n = 0;
void printElements() {
printf("< ");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf(">\n");
}
void keyboardInput() {
printf("n = ");
scanf_s("%d", &n);
printf("ââåäèòå %d çíà÷åíèÿ: ", n);
for (int i = 0; i < n; i++) {
scanf_s("%d", &arr[i]);
}
}
void oddsX10() {
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 1) {
arr[i] *= 10;
}
}
}
int findMin() {
int min = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
int findMore10() {
int count = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > 10) {
count += 1;
}
}
return count;
}
int findLastEven() {
for (int i = n - 1; i >= 0; i--) {
if (arr[i] % 2 == 0) {
return i;
}
}
return 0;
}
int findIndexMin() {
int min = 0;
for (int i = 1; i < n; i++) {
if (arr[i] < arr[min]) {
min = i;
}
}
return min;
}
int findIndexMax() {
int max = 0;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[max]) {
max = i;
}
}
return max;
}
void findEvenDigits() {
int count = 0;
for (int i = findIndexMin(); i >= 0; i--) {
if (arr[i] % 2 == 0) {
count += 1;
}
}
printf("%d ëåâåå ìèíèìàëüíîãî", count);
}
void oddsXMinus1() {
for (int i = 0; i < n; i++) {
arr[i] *= -1;
}
}
void changeDigitLess4() {
for (int i = 0; i < n; i++) {
if (arr[i] < 4) {
arr[i] = 4;
}
}
}
void oddsReplace1() {
for (int i = 0; i < n; i++) {
arrHelp[i] = arr[i];
}
for (int i = 1; i < (n - 1); i++) {
if ((arrHelp[i - 1] % 2 == 0) && (arrHelp[i + 1] % 2 == 0)) {
arr[i] = 1;
}
}
}
void X10BetweenMinMax() {
for (int i = findIndexMin() + 1; i < findIndexMax(); i++) {
arr[i] *= 10;
}
}
void X100BetweenFirstLastEven() {
int firstEvenIndex;
int lastEvenIndex;
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
firstEvenIndex = i;
break;
}
}
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
lastEvenIndex = i;
}
}
for (int i = firstEvenIndex + 1; i < lastEvenIndex; i++) {
arr[i] *= 100;
}
}
void deleteElement(int delIndex) {
if (delIndex >= 0 && delIndex < n) {
for (int i = delIndex; i < n; i++) {
arr[i] = arr[i + 1];
}
n--;
}
}
void insertElement(int insIndex, int value) {
if (insIndex >= 0 && insIndex < n) {
for (int i = n; i > insIndex; i--) {
arr[i] = arr[i - 1];
}
arr[insIndex] = value;
n++;
}
}
void delMin() {
int min = findIndexMin();
for (int i = min; i < n; i++) {
arr[i] = arr[i + 1];
}
n--;
}
void insert0BeforeMin() {
int min = findIndexMin();
for (int i = n; i > min; i--) {
arr[i] = arr[i - 1];
}
arr[min] = 0;
n++;
}
void delAllEven() {
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
for (int j = i; j < n; j++) {
arr[j] = arr[j + 1];
}
n--;
}
}
}
int indexMaxEven() {
int flag = 0;
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
flag = 1;
break;
}
}
if (flag == 1) {
int max = 0;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[max] && arr[i] % 2 == 0) {
max = i;
}
}
return max;
}
printf(" ìàññèâå íåò ÷åòíûõ ÷èñåë");
}
void insAfterMaxEven0() {
int maxEven = indexMaxEven();
if (arr[maxEven] % 2 == 0 && arr[maxEven] != 0) {
for (int i = n; i > maxEven + 1; i--) {
arr[i] = arr[i - 1];
}
arr[maxEven + 1] = 0;
n++;
}
}
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int item;
do {
printf("\n");
printf("------------------------------\n");
printf("Ñîäåðæèìîå ìàññèâà:");
printElements();
printf("Âûáåðèòå íóæíóþ âàì îïåðàöèþ:\n");
printf("1: Ââåñòè ñ êëàâèàòóðû ìàññèâ\n");
printf("2: x10 äëÿ âñåõ íå÷åòíûõ ýëåìåíòîâ\n");
printf("3: Íàéòè ìèíèìàëüíûé ýëåìåíò\n");
printf("4: Ñêîëüêî ýëåìåíòîâ > 10\n");
printf("5: 2x äëÿ ïîñëåäíåãî ÷åòíîãî\n");
printf("6: Ñêîëüêî ÷¸òíûõ ëåâåå ìèíèìàëüíîãî\n");
printf("7: Âñå ÷åòíûå ýëåìåíòû óìíîæèòü íà -1\n");
printf("8: Âñå ýëåìåíòû < 4 çàìåíèòü íà 4\n");
printf("9: Âñå íå÷åòíûå ýëåìåíòû çàìåíèòü íà 1\n");
printf("10: Âñå ýëåìåíòû ìåæäó ìàêñèìàëüíûì è ìèíèìàëüíûì óâåëè÷èòü â 10 ðàç\n");
printf("11: Âñå ýëåìåíòû ìåæäó ïåðâûì è ïîñëåäíèì ÷åòíûì óâåëè÷èòü â 100 ðàç\n");
printf("12: Óäàëèòü ýëåìåíò\n");
printf("13: Âñòàâèòü ýëåìåíò\n");
printf("14: Óäàëèòü ìèíèìàëüíûé ýëåìåíò\n");
printf("15: Ïåðåä ìèíèìàëüíûì ýëåìåíòîì âñòàâèòü 0\n");
printf("16: Óäàëèòü âñå ÷åòíûå ýëåìåíòû\n");
printf("17: Âñòàâèòü ïîñëå ìàêñèìàëüíîãî èç ÷åòíûõ ýëåìåíòîâ 0\n");
printf("\n");
printf("0: Âûéòè èç ïðîãðàììû\n");
printf("Âûáðàííàÿ îïåðàöèÿ >>>>>> ");
scanf_s("%d", &item);
switch(item) {
case 1:
keyboardInput();
break;
case 2:
oddsX10();
break;
case 3:
{
int min = findMin();
printf("ìèí = %d\n", min);
}
break;
case 4:
{
int more10 = findMore10();
printf("%d ýëåìåíòîâ áîëüøå ÷åì 10\n", more10);
}
break;
case 5:
{
int index = findLastEven();
if (index >= 0) {
arr[index] *= 2;
}
}
break;
case 6:
findEvenDigits();
break;
case 7:
oddsXMinus1();
break;
case 8:
changeDigitLess4();
break;
case 9:
oddsReplace1();
break;
case 10:
X10BetweenMinMax();
break;
case 11:
X100BetweenFirstLastEven();
break;
case 12:
{
printf("Èíäåêñ óäàëÿåìîãî ýëåìåíòà = ");
int index;
scanf_s("%d", &index);
deleteElement(index);
}
break;
case 13:
{
printf("Èíäåêñ âñòàâëÿåìîãî ýëåìåíòà = ");
int index;
scanf_s("%d", &index);
printf("Çíà÷åíèå âñòàâëÿåìîãî ýëåìåíòà = ");
int value;
scanf_s("%d", &value);
insertElement(index, value);
}
break;
case 14:
delMin();
break;
case 15:
insert0BeforeMin();
break;
case 16:
delAllEven();
break;
case 17:
insAfterMaxEven0();
break;
};
} while (item != 0);
return 0;
}

135
lab13/lab13.vcxproj Normal file
View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{fe10dfb9-9083-48de-81b1-cc1fc4ea111e}</ProjectGuid>
<RootNamespace>lab13</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="FileName.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="FileName.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
</Project>