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 diff --git a/sem2/TaradaySK/homework_4/FileProcessor.cpp b/sem2/TaradaySK/homework_4/FileProcessor.cpp new file mode 100644 index 00000000..e219274b --- /dev/null +++ b/sem2/TaradaySK/homework_4/FileProcessor.cpp @@ -0,0 +1,55 @@ +#include "FileProcessor.h" + +#include +#include +#include +#include +#include +#include +#include + +void runRandomProcessing() { + std::string line = "*******************************************************"; + std::ofstream output("output.txt"); + if (!output.is_open()) return; + std::vector numbers(20); + std::mt19937 gen(std::random_device{}()); + std::uniform_int_distribution<> dist(-50, 100); + std::generate(numbers.begin(), numbers.end(), [&]() { return dist(gen); }); + output << line << "\nИсходный вектор\n"; + std::copy(numbers.begin(), numbers.end(), + std::ostream_iterator(output, " ")); + auto itMin = std::min_element(numbers.begin(), numbers.end()); + auto itMax = std::max_element(numbers.begin(), numbers.end()); + output << "\n" << line << "\nMin: " << *itMin << ", Max: " << *itMax << "\n"; + std::sort(numbers.begin(), numbers.end()); + output << line << "\nОтсортированный вектор\n"; + std::copy(numbers.begin(), numbers.end(), + std::ostream_iterator(output, " ")); + long long pos = std::count_if(numbers.begin(), numbers.end(), + [](int n) { return n > 0; }); + long long neg = std::count_if(numbers.begin(), numbers.end(), + [](int n) { return n < 0; }); + long long zero = std::count_if(numbers.begin(), numbers.end(), + [](int n) { return n == 0; }); + output << "\n" + << line << "\nПоложительных: " << pos << ", Отрицательных: " << neg + << ", Нулей: " << zero << "\n"; + double sum = std::accumulate(numbers.begin(), numbers.end(), 0.0); + output << line << "\nСреднее: " << sum / numbers.size() << "\n"; + numbers.erase(std::remove_if(numbers.begin(), numbers.end(), + [](int n) { return n % 2 == 0; }), + numbers.end()); + output << line << "\nБез чётных\n"; + std::copy(numbers.begin(), numbers.end(), + std::ostream_iterator(output, " ")); + std::sort(numbers.begin(), numbers.end()); + std::vector unique_vec; + std::unique_copy(numbers.begin(), numbers.end(), + std::back_inserter(unique_vec)); + output << "\n" << line << "\nУникальные\n"; + std::copy(unique_vec.begin(), unique_vec.end(), + std::ostream_iterator(output, " ")); + output << "\n" << line; + output.close(); +} diff --git a/sem2/TaradaySK/homework_4/FileProcessor.h b/sem2/TaradaySK/homework_4/FileProcessor.h new file mode 100644 index 00000000..2441dd55 --- /dev/null +++ b/sem2/TaradaySK/homework_4/FileProcessor.h @@ -0,0 +1,4 @@ +#ifndef FILE_PROCESSOR_H +#define FILE_PROCESSOR_H +void runRandomProcessing(); +#endif diff --git a/sem2/TaradaySK/homework_4/main.cpp b/sem2/TaradaySK/homework_4/main.cpp new file mode 100644 index 00000000..b18cd9c1 --- /dev/null +++ b/sem2/TaradaySK/homework_4/main.cpp @@ -0,0 +1,8 @@ +п»ї#include + +#include "FileProcessor.h" +int main() { + setlocale(LC_ALL, "Russian"); + runRandomProcessing(); + return 0; +} diff --git a/sem2/TaradaySK/homework_4/output.txt b/sem2/TaradaySK/homework_4/output.txt new file mode 100644 index 00000000..4de92337 --- /dev/null +++ b/sem2/TaradaySK/homework_4/output.txt @@ -0,0 +1,19 @@ +******************************************************* +Исходный вектор +93 75 -44 17 41 58 76 4 -24 35 51 38 57 46 -23 17 33 -32 73 -2 +******************************************************* +Min: -44, Max: 93 +******************************************************* +Отсортированный вектор +-44 -32 -24 -23 -2 4 17 17 33 35 38 41 46 51 57 58 73 75 76 93 +******************************************************* +Положительных: 15, Отрицательных: 5, Нулей: 0 +******************************************************* +Среднее: 29.45 +******************************************************* +Без чётных +-23 17 17 33 35 41 51 57 73 75 93 +******************************************************* +Уникальные +-23 17 33 35 41 51 57 73 75 93 +******************************************************* \ No newline at end of file