From 467c8466df9de41a38a53b95007fe90b2036cd0a Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 19 Dec 2023 22:51:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D1=8C=D1=82?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bits 4.sln | 31 ++++++++ bits 4/bits 4.cpp | 77 +++++++++++++++++++ bits 4/bits 4.vcxproj | 135 ++++++++++++++++++++++++++++++++++ bits 4/bits 4.vcxproj.filters | 22 ++++++ 4 files changed, 265 insertions(+) create mode 100644 bits 4.sln create mode 100644 bits 4/bits 4.cpp create mode 100644 bits 4/bits 4.vcxproj create mode 100644 bits 4/bits 4.vcxproj.filters diff --git a/bits 4.sln b/bits 4.sln new file mode 100644 index 0000000..b0b274b --- /dev/null +++ b/bits 4.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bits 4", "bits 4\bits 4.vcxproj", "{CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}" +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 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Debug|x64.ActiveCfg = Debug|x64 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Debug|x64.Build.0 = Debug|x64 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Debug|x86.ActiveCfg = Debug|Win32 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Debug|x86.Build.0 = Debug|Win32 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Release|x64.ActiveCfg = Release|x64 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Release|x64.Build.0 = Release|x64 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Release|x86.ActiveCfg = Release|Win32 + {CEDC70AD-DC0C-436A-B728-EF4CC32E0C81}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {139BCBC1-22A6-49BB-9FA2-41ED0A385CE9} + EndGlobalSection +EndGlobal diff --git a/bits 4/bits 4.cpp b/bits 4/bits 4.cpp new file mode 100644 index 0000000..a159f1d --- /dev/null +++ b/bits 4/bits 4.cpp @@ -0,0 +1,77 @@ +#include +#include +#include + +using namespace std; + +int main() { + char fileName[260]; + cin.getline(fileName, 260); + + if (strchr(fileName, '*') || strchr(fileName, '"') || strchr(fileName, '<') || + strchr(fileName, '>') || strchr(fileName, '?') || strchr(fileName, '|') || + strchr(fileName + 2, ':') || (fileName[0] == ':')) { + cout << "Invalid path" << endl; + return 1; + } + + if (fileName[1] == ':' && (!isalpha(fileName[0]) || fileName[2] != '\\')) { + cout << "Invalid path" << endl; + return 1; + } + + if (strrchr(fileName, '.') && (strrchr(fileName, '.') > strrchr(fileName, '\\')) && (strrchr(fileName, '.') > strrchr(fileName, '/'))) { + char* ext = strrchr(fileName, '.') + 1; + + if (strlen(ext) != 3) { + cout << "Invalid path" << endl; + return 1; + } + + ext[0] = tolower(ext[0]); + ext[1] = tolower(ext[1]); + ext[2] = tolower(ext[2]); + + if (strncmp(ext, "txt", 3) != 0) { + cout << "Invalid path" << endl; + return 1; + } + } + else { + strcat_s(fileName, 260, ".txt"); + } + + ifstream fin; + fin.open(fileName, ios_base::binary); + + if (!fin.is_open()) { + cout << "Can't open file" << endl; + return 1; + } + + fin.seekg(0, ios_base::_Seekend); + size_t size = fin.tellg(); + fin.seekg(0, ios_base::_Seekbeg); + + char* buf = new char[size]; + fin.read(buf, size); + fin.close(); + + char str[64]; + cin.getline(str, 64); + + char* found = buf - 1; + uint16_t cnt = -1; + + do { + ++cnt; + ++found; + found = strstr(found, str); + } while (found); + + delete[] buf; + cout << cnt << " occurrences found" << endl; + cin.get(); + + return 0; +} diff --git a/bits 4/bits 4.vcxproj b/bits 4/bits 4.vcxproj new file mode 100644 index 0000000..7fc1486 --- /dev/null +++ b/bits 4/bits 4.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {cedc70ad-dc0c-436a-b728-ef4cc32e0c81} + bits4 + 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/bits 4/bits 4.vcxproj.filters b/bits 4/bits 4.vcxproj.filters new file mode 100644 index 0000000..8e0811d --- /dev/null +++ b/bits 4/bits 4.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