From 4c4a5b2693bf452dc509aa0aa3f64162a75517fd Mon Sep 17 00:00:00 2001 From: oltnd Date: Fri, 22 Nov 2024 23:12:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20main.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.cpp => main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) rename 1.cpp => main.cpp (70%) diff --git a/1.cpp b/main.cpp similarity index 70% rename from 1.cpp rename to main.cpp index 8afaa74..e3fedad 100644 --- a/1.cpp +++ b/main.cpp @@ -2,7 +2,8 @@ #include #include #include - +#include +#include using namespace std; int gcdDivision(int a, int b) { @@ -59,7 +60,7 @@ void findLeastFrequentVowel(const string& filePath) { file.close(); int minCount = numeric_limits::max(); - char leastVowel = '\0'; + char leastVowel; for (int i = 0; i < 6; ++i) { if (counts[i] > 0 && counts[i] < minCount) { minCount = counts[i]; @@ -76,7 +77,7 @@ void findLeastFrequentVowel(const string& filePath) { } } -void z3() { +void z3_22() { string filePath; filePath = "txt.txt"; findLeastFrequentVowel(filePath); @@ -104,9 +105,51 @@ void z1launcher() { } } + +void findWordCombination(const string& fileName, const string& combination) { + ifstream file(fileName); + if (!file.is_open()) { + cerr << "Не удалось открыть файл: " << fileName << endl; + return; + } + + string line; + size_t lineNumber = 0; + bool found = false; + + while (getline(file, line)) { + ++lineNumber; + // Проверяем, содержит ли строка указанное сочетание слов + if (line.find(combination) != string::npos) { + found = true; + cout << "Найдено в строке " << lineNumber << ": " << line << endl; + } + } + + if (!found) { + cout << "Сочетание \"" << combination << "\" не найдено в файле." << endl; + } + + file.close(); +} + +void z3_16() { + string fileName, combination; + + fileName = "txt2.txt"; + + + cout << "Введите сочетание слов для поиска: "; + cin >> combination; + + findWordCombination(fileName, combination); + + +} + int main() { setlocale(LC_ALL, ""); /*z1launcher();*/ - z3(); + z3_16(); return 0; }