diff --git a/sem2/TaradaySK/homework_3/FileProcessor.cpp b/sem2/TaradaySK/homework_3/FileProcessor.cpp new file mode 100644 index 00000000..f295c88e --- /dev/null +++ b/sem2/TaradaySK/homework_3/FileProcessor.cpp @@ -0,0 +1,73 @@ +#include "FileProcessor.h" + +#include +#include +#include +#include +#include + +void processFiles() { + std::vector lines; + std::string text; + std::string line = "------------------------------------------------------"; + + std::ifstream input("input.txt"); + if (input.is_open()) { + while (std::getline(input, text)) { + lines.push_back(text); + } + } + input.close(); + + std::ofstream output("output.txt"); + if (output.is_open()) { + output << line << "\n(-_-) Исходный вектор(-_-)\n"; + for (const auto& s : lines) output << s << "\n"; + + int threshold; + std::cout << "Введите порог длины: "; + std::cin >> threshold; + lines.erase(std::remove_if(lines.begin(), lines.end(), + [threshold](const std::string& s) { + return s.length() < (size_t)threshold; + }), + lines.end()); + output << line << "\n(-_-) После удаления строк < " << threshold + << " (-_-)\n"; + for (const auto& s : lines) output << s << "\n"; + + for (auto& s : lines) { + for (char& c : s) + if (c == ' ') c = '_'; + } + output << line << "\n(-_-) После замены пробелов на _ (-_-)\n"; + for (const auto& s : lines) output << s << "\n"; + + std::string searchWord; + std::cout << "Введите слово для поиска: "; + std::cin >> searchWord; + auto it = std::find_if(lines.begin(), lines.end(), + [&searchWord](const std::string& s) { + return s.find(searchWord) != std::string::npos; + }); + output << line << "\n(-_-) Результат поиска по " << searchWord + << " (-_-)\n"; + if (it != lines.end()) + output << *it << "\n"; + else + output << "Слово не найдено\n"; + + long long total = 0; + for (const auto& s : lines) { + for (char c : s) + if (c != '_') total++; + } + output << line << "\n(-_-) Символов без _ (-_-)\n" << total << "\n"; + + std::vector lengths; + for (const auto& s : lines) lengths.push_back((int)s.length()); + output << line << "\n(-_-) Длины строк (-_-)\n"; + for (int l : lengths) output << l << " "; + } + output.close(); +} diff --git a/sem2/TaradaySK/homework_3/FileProcessor.h b/sem2/TaradaySK/homework_3/FileProcessor.h new file mode 100644 index 00000000..422358ba --- /dev/null +++ b/sem2/TaradaySK/homework_3/FileProcessor.h @@ -0,0 +1,8 @@ +#ifndef FILE_PROCESSOR_H +#define FILE_PROCESSOR_H + +#include + +void processFiles(); + +#endif \ No newline at end of file diff --git a/sem2/TaradaySK/homework_3/input.txt b/sem2/TaradaySK/homework_3/input.txt new file mode 100644 index 00000000..3f95ed8e --- /dev/null +++ b/sem2/TaradaySK/homework_3/input.txt @@ -0,0 +1,6 @@ +Hello world +C++ programming is fun +Lambda expressions +STL algorithms +Short +A very long string just for testing purposes \ No newline at end of file diff --git a/sem2/TaradaySK/homework_3/main.cpp b/sem2/TaradaySK/homework_3/main.cpp new file mode 100644 index 00000000..f8158f4c --- /dev/null +++ b/sem2/TaradaySK/homework_3/main.cpp @@ -0,0 +1,9 @@ +п»ї#include + +#include "FileProcessor.h" + +int main() { + setlocale(LC_ALL, "Russian"); + processFiles(); + return 0; +} \ No newline at end of file diff --git a/sem2/TaradaySK/homework_3/output.txt b/sem2/TaradaySK/homework_3/output.txt new file mode 100644 index 00000000..31b414cd --- /dev/null +++ b/sem2/TaradaySK/homework_3/output.txt @@ -0,0 +1,29 @@ +------------------------------------------------------ +(-_-) Исходный вектор(-_-) +Hello world +C++ programming is fun +Lambda expressions +STL algorithms +Short +A very long string just for testing purposes +------------------------------------------------------ +(-_-) После удаления строк < 12 (-_-) +C++ programming is fun +Lambda expressions +STL algorithms +A very long string just for testing purposes +------------------------------------------------------ +(-_-) После замены пробелов на _ (-_-) +C++_programming_is_fun +Lambda_expressions +STL_algorithms +A_very_long_string_just_for_testing_purposes +------------------------------------------------------ +(-_-) Результат поиска по STL (-_-) +STL_algorithms +------------------------------------------------------ +(-_-) Символов без _ (-_-) +86 +------------------------------------------------------ +(-_-) Длины строк (-_-) +22 18 14 44 \ No newline at end of file