diff --git a/arrayOFNumbers/arrayOFNumbers.sln b/arrayOFNumbers/arrayOFNumbers.sln new file mode 100644 index 0000000..170cff3 --- /dev/null +++ b/arrayOFNumbers/arrayOFNumbers.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "arrayOFNumbers", "arrayOFNumbers\arrayOFNumbers.vcxproj", "{82B95909-9910-4ED3-8EB1-1735D9D0D34B}" +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 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Debug|x64.ActiveCfg = Debug|x64 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Debug|x64.Build.0 = Debug|x64 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Debug|x86.ActiveCfg = Debug|Win32 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Debug|x86.Build.0 = Debug|Win32 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Release|x64.ActiveCfg = Release|x64 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Release|x64.Build.0 = Release|x64 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Release|x86.ActiveCfg = Release|Win32 + {82B95909-9910-4ED3-8EB1-1735D9D0D34B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DCB43279-7E4D-409C-AF4E-9A003FFFC193} + EndGlobalSection +EndGlobal diff --git a/arrayOFNumbers/arrayOFNumbers/arrayOFNumbers.vcxproj b/arrayOFNumbers/arrayOFNumbers/arrayOFNumbers.vcxproj new file mode 100644 index 0000000..0ab21a9 --- /dev/null +++ b/arrayOFNumbers/arrayOFNumbers/arrayOFNumbers.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {82b95909-9910-4ed3-8eb1-1735d9d0d34b} + arrayOFNumbers + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + 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/arrayOFNumbers/arrayOFNumbers/arrayOFNumbers.vcxproj.filters b/arrayOFNumbers/arrayOFNumbers/arrayOFNumbers.vcxproj.filters new file mode 100644 index 0000000..e570507 --- /dev/null +++ b/arrayOFNumbers/arrayOFNumbers/arrayOFNumbers.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 diff --git a/arrayOFNumbers/arrayOFNumbers/arrayOfNumbers.c b/arrayOFNumbers/arrayOFNumbers/arrayOfNumbers.c new file mode 100644 index 0000000..b857f3e --- /dev/null +++ b/arrayOFNumbers/arrayOFNumbers/arrayOfNumbers.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +bool test() +{ + int arrayOFNumber[10] = {199, 36, 123, 1, 2, 6, 8, 9, 7, 10}; + int sum[10] = {0}; + return largestSun(arrayOFNumber, sum, 10) == 0; + +} + +int largestSun(int *array,int* sum,int numberOfElements) +{ + for (int i = 0; i < numberOfElements; i++) + { + while (array[i] > 0) + { + sum[i] += array[i] % 10; + array[i] /= 10; + } + } + int temporary = sum[0]; + int j = 0; + for (int i = 1; i < numberOfElements; i++) + { + if (sum[i] > temporary) + { + temporary = sum[i]; + j = i; + } + } + return j; +} +int main() +{ + setlocale(LC_ALL, "rus"); + if (!test()) + { + return -1; + } + setlocale(LC_ALL, "rus"); + int numberOfElements = 0; + printf(" "); + scanf_s("%d", &numberOfElements); + int* array = calloc(numberOfElements, sizeof(int)); + if (array == 0) + { + return -1; + } + int* sum = calloc(numberOfElements, sizeof(int)); + if (sum == 0) + { + return -1; + } + for (int i = 0; i < numberOfElements; i++) + { + array[i] = rand(); + } + int k = largestSun(array,sum, numberOfElements); + printf(" %d %d", k, array[k]); + free(array); + free(sum); +} \ No newline at end of file diff --git a/epeatingElements/epeatingElements.sln b/epeatingElements/epeatingElements.sln new file mode 100644 index 0000000..5895760 --- /dev/null +++ b/epeatingElements/epeatingElements.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "epeatingElements", "epeatingElements\epeatingElements.vcxproj", "{9CAAE94E-3BD7-405C-9490-4567B6DC22CF}" +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 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Debug|x64.ActiveCfg = Debug|x64 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Debug|x64.Build.0 = Debug|x64 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Debug|x86.ActiveCfg = Debug|Win32 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Debug|x86.Build.0 = Debug|Win32 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Release|x64.ActiveCfg = Release|x64 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Release|x64.Build.0 = Release|x64 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Release|x86.ActiveCfg = Release|Win32 + {9CAAE94E-3BD7-405C-9490-4567B6DC22CF}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F5178FEF-DC23-41A3-9F99-E0104B4F0378} + EndGlobalSection +EndGlobal diff --git a/epeatingElements/epeatingElements/epeatingElements.vcxproj b/epeatingElements/epeatingElements/epeatingElements.vcxproj new file mode 100644 index 0000000..43982b6 --- /dev/null +++ b/epeatingElements/epeatingElements/epeatingElements.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {9caae94e-3bd7-405c-9490-4567b6dc22cf} + epeatingElements + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + 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/epeatingElements/epeatingElements/epeatingElements.vcxproj.filters b/epeatingElements/epeatingElements/epeatingElements.vcxproj.filters new file mode 100644 index 0000000..a148552 --- /dev/null +++ b/epeatingElements/epeatingElements/epeatingElements.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {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 diff --git a/epeatingElements/epeatingElements/main.c b/epeatingElements/epeatingElements/main.c new file mode 100644 index 0000000..ec558e4 --- /dev/null +++ b/epeatingElements/epeatingElements/main.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include "repeatingElements.h" +#include "test.h" + +int main() +{ + FILE* file = NULL; + errno_t err; + err = fopen_s(&file, "qwerty.txt", "r"); + if (file == NULL || err == 1) + { + printf("file not found!"); + return -1; + } + fileInput(file); +} \ No newline at end of file diff --git a/epeatingElements/epeatingElements/qwert.txt b/epeatingElements/epeatingElements/qwert.txt new file mode 100644 index 0000000..0433c48 --- /dev/null +++ b/epeatingElements/epeatingElements/qwert.txt @@ -0,0 +1 @@ +xxxxyxyxyxyxyxy \ No newline at end of file diff --git a/epeatingElements/epeatingElements/qwerty.txt b/epeatingElements/epeatingElements/qwerty.txt new file mode 100644 index 0000000..02ed955 --- /dev/null +++ b/epeatingElements/epeatingElements/qwerty.txt @@ -0,0 +1 @@ +asdfgggg \ No newline at end of file diff --git a/epeatingElements/epeatingElements/repeatingElements.c b/epeatingElements/epeatingElements/repeatingElements.c new file mode 100644 index 0000000..b121f2d --- /dev/null +++ b/epeatingElements/epeatingElements/repeatingElements.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include"repeatingElements.h" + +void fileInput(FILE* file) +{ + int counter = 0; + char buffer = 0; + char array[100] = { '\0' }; + while (!feof(file)) + { + const int readBytes = fscanf_s(file, "%c", &buffer, 1); + if (readBytes < 0) + { + break; + } + array[counter] = buffer; + counter++; + } + fclose(file); + int k = 0; + int i = 0; + while (array[i] != '\0') + { + const int temporary = array[i]; + const int temp = i; + printf("%c", array[i]); + for (int j = 1; j <= counter - temp; j++) + { + if (temporary == array[j + temp]) + { + i++; + } + else + { + i++; + break; + } + } + } +} \ No newline at end of file diff --git a/epeatingElements/epeatingElements/repeatingElements.h b/epeatingElements/epeatingElements/repeatingElements.h new file mode 100644 index 0000000..0e2f25f --- /dev/null +++ b/epeatingElements/epeatingElements/repeatingElements.h @@ -0,0 +1,5 @@ +#pragma once +#include +#include + +void fileInput(FILE* file); diff --git a/epeatingElements/epeatingElements/test.c b/epeatingElements/epeatingElements/test.c new file mode 100644 index 0000000..2c210af --- /dev/null +++ b/epeatingElements/epeatingElements/test.c @@ -0,0 +1,29 @@ +#include "test.h" +#include "repeatingElements.h" +#include +#include + +bool checkArray(char* array, int counter) +{ + for (int i = 0; i < counter - 1; i++) + { + if (array[i] == array[i + 1]) + { + return false; + } + } + return true; +} +bool checkRepeatingElements() +{ + FILE* secondFile = NULL; + errno_t err; + err = fopen_s(&secondFile, "qwert.txt", "r"); + if (secondFile == NULL || err == 1) + { + printf("file not found!"); + return -1; + } + fileInput(secondFile); + return true; +} \ No newline at end of file diff --git a/epeatingElements/epeatingElements/test.h b/epeatingElements/epeatingElements/test.h new file mode 100644 index 0000000..4fa237f --- /dev/null +++ b/epeatingElements/epeatingElements/test.h @@ -0,0 +1,4 @@ +#pragma once +#include + +bool checkRepeatingElements(); \ No newline at end of file diff --git a/selectionSort/selectionSort.sln b/selectionSort/selectionSort.sln new file mode 100644 index 0000000..f8c3762 --- /dev/null +++ b/selectionSort/selectionSort.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "selectionSort", "selectionSort\selectionSort.vcxproj", "{AEA84333-9D11-413E-BB55-0FED2B69EA39}" +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 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Debug|x64.ActiveCfg = Debug|x64 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Debug|x64.Build.0 = Debug|x64 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Debug|x86.ActiveCfg = Debug|Win32 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Debug|x86.Build.0 = Debug|Win32 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Release|x64.ActiveCfg = Release|x64 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Release|x64.Build.0 = Release|x64 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Release|x86.ActiveCfg = Release|Win32 + {AEA84333-9D11-413E-BB55-0FED2B69EA39}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {43EBF396-6D68-4EAD-BD9A-9EA3C631F9A9} + EndGlobalSection +EndGlobal diff --git a/selectionSort/selectionSort/choiseSort.c b/selectionSort/selectionSort/choiseSort.c new file mode 100644 index 0000000..8627286 --- /dev/null +++ b/selectionSort/selectionSort/choiseSort.c @@ -0,0 +1,23 @@ +#include "choiseSort.h" + +void sortChoise(int* arrayOfNumber, int numberOfElement) +{ + for (int i = 0; i < numberOfElement - 1; i++) + { + int count = 0; + int temporary = arrayOfNumber[i]; + for (int j = i + 1; j <= numberOfElement - 1; j++) + { + if (arrayOfNumber[j] < temporary) + { + temporary = arrayOfNumber[j]; + count = j; + } + } + if (temporary != arrayOfNumber[i]) + { + arrayOfNumber[count] = arrayOfNumber[i]; + arrayOfNumber[i] = temporary; + } + } +} \ No newline at end of file diff --git a/selectionSort/selectionSort/choiseSort.h b/selectionSort/selectionSort/choiseSort.h new file mode 100644 index 0000000..1a432e1 --- /dev/null +++ b/selectionSort/selectionSort/choiseSort.h @@ -0,0 +1,3 @@ +#pragma once + +void sortChoise(int* arrayOfNumber, int numberOfElement); diff --git a/selectionSort/selectionSort/main.c b/selectionSort/selectionSort/main.c new file mode 100644 index 0000000..359ca68 --- /dev/null +++ b/selectionSort/selectionSort/main.c @@ -0,0 +1,25 @@ +#include +#include +#include "choiseSort.h" +#include "test.h" + +int main() +{ + setlocale(LC_ALL, "rus"); + if (!testSorthoice()) + { + return -1; + } + setlocale(LC_ALL, "rus"); + int arrayOfNumber[10] = { 0 }; + for (int i = 0; i < 10; i++) + { + printf(" %d\n", i); + scanf_s("%d", &arrayOfNumber[i]); + } + sortChoise(arrayOfNumber, 10); + for (int i = 0; i < 10; i++) + { + printf("%d ", arrayOfNumber[i]); + } +} \ No newline at end of file diff --git a/selectionSort/selectionSort/selectionSort.vcxproj b/selectionSort/selectionSort/selectionSort.vcxproj new file mode 100644 index 0000000..a3300a9 --- /dev/null +++ b/selectionSort/selectionSort/selectionSort.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {aea84333-9d11-413e-bb55-0fed2b69ea39} + selectionSort + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + 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/selectionSort/selectionSort/selectionSort.vcxproj.filters b/selectionSort/selectionSort/selectionSort.vcxproj.filters new file mode 100644 index 0000000..a68f4be --- /dev/null +++ b/selectionSort/selectionSort/selectionSort.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {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 diff --git a/selectionSort/selectionSort/test.c b/selectionSort/selectionSort/test.c new file mode 100644 index 0000000..0804a93 --- /dev/null +++ b/selectionSort/selectionSort/test.c @@ -0,0 +1,37 @@ +#include "test.h" +#include "choiseSort.h" + +bool checkSort(int* arrayOfNumbers, int numberOfElement) +{ + for (int i = 0; i < numberOfElement - 1; i++) + { + if (arrayOfNumbers[i] > arrayOfNumbers[i + 1]) + { + return false; + } + } + return true; +} +bool testSorthoice() +{ + // + int array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + sortChoise(array, 10); + + // + int arrayOfEqualElements[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + sortChoise(arrayOfEqualElements, 10); + + // + int arrayOfOneNumber[1] = { 15 }; + sortChoise(arrayOfOneNumber, 1); + + // + int arrayOfZeroNumber[1] = { 15 }; + sortChoise(arrayOfZeroNumber, 0); + + return checkSort(array, 10) + && checkSort(arrayOfEqualElements, 10) + && checkSort(arrayOfOneNumber, 1) + && checkSort(arrayOfZeroNumber, 0); +} \ No newline at end of file diff --git a/selectionSort/selectionSort/test.h b/selectionSort/selectionSort/test.h new file mode 100644 index 0000000..3685ef1 --- /dev/null +++ b/selectionSort/selectionSort/test.h @@ -0,0 +1,4 @@ +#pragma once +#include + +bool testSorthoice();