Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions sem2/TaradaySK/homework_3/FileProcessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "FileProcessor.h"

#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

void processFiles() {
std::vector<std::string> 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<int> lengths;
for (const auto& s : lines) lengths.push_back((int)s.length());
output << line << "\n(-_-) ����� ����� (-_-)\n";
for (int l : lengths) output << l << " ";
}
output.close();
}
8 changes: 8 additions & 0 deletions sem2/TaradaySK/homework_3/FileProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef FILE_PROCESSOR_H
#define FILE_PROCESSOR_H

#include <string>

void processFiles();

#endif
6 changes: 6 additions & 0 deletions sem2/TaradaySK/homework_3/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hello world
C++ programming is fun
Lambda expressions
STL algorithms
Short
A very long string just for testing purposes
9 changes: 9 additions & 0 deletions sem2/TaradaySK/homework_3/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

#include "FileProcessor.h"

int main() {
setlocale(LC_ALL, "Russian");
processFiles();
return 0;
}
29 changes: 29 additions & 0 deletions sem2/TaradaySK/homework_3/output.txt
Original file line number Diff line number Diff line change
@@ -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