diff --git a/lab13.sln b/lab13.sln new file mode 100644 index 0000000..32d49df --- /dev/null +++ b/lab13.sln @@ -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 diff --git a/lab13/FileName.c b/lab13/FileName.c new file mode 100644 index 0000000..0d85d21 --- /dev/null +++ b/lab13/FileName.c @@ -0,0 +1,340 @@ +#include +#include + +#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; +} \ No newline at end of file diff --git a/lab13/lab13.vcxproj b/lab13/lab13.vcxproj new file mode 100644 index 0000000..157faf9 --- /dev/null +++ b/lab13/lab13.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {fe10dfb9-9083-48de-81b1-cc1fc4ea111e} + lab13 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/lab13/lab13.vcxproj.filters b/lab13/lab13.vcxproj.filters new file mode 100644 index 0000000..f768a36 --- /dev/null +++ b/lab13/lab13.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file