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
6 changes: 6 additions & 0 deletions sem2/OvsyannikovaVA/MINI_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
103 changes: 103 additions & 0 deletions sem2/OvsyannikovaVA/MINI_3/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int main() {
char* locale = setlocale(LC_ALL, "");

std::ifstream file("input.txt");
std::vector<std::string> lines;
std::string line;

if (file.is_open()) {
while (std::getline(file, line)) {
lines.push_back(line);
}
file.close();
}

int porog;

std::cout << "������, ����� ������� ������ ������, ��������. ������� �����: ";
std::cin >> porog;

auto f1 = [porog](std::string s) { return s.length() < porog; };
std::vector<std::string> poroglines = lines;
poroglines.erase(std::remove_if(poroglines.begin(), poroglines.end(), f1),
poroglines.end());

auto f2 = [](std::string s) {
std::replace(s.begin(), s.end(), ' ', '_');
return s;
};
std::vector<std::string> lineswospace;
for (auto line : lines) {
lineswospace.push_back(f2(line));
}

std::string word;
std::cout << "������� ����� ��� ������: ";
std::cin >> word;

auto f3 = [&word](std::string str) -> bool {
return str.find(word) != std::string::npos;
};

std::vector<std::string> found;
for (auto line : lines) {
if (f3(line)) {
found.push_back(line);
}
}

auto f4 = [](char c) { return c != '_'; };
int allchars = 0;

for (auto str : lines) {
allchars += std::count_if(str.begin(), str.end(), f4);
}

std::vector<int> lengthstr;
auto f5 = [](std::string str) -> int { return str.length(); };

for (auto str : lines) {
lengthstr.push_back(f5(str));
}

// ����
std::ofstream file2("output.txt");

file2 << "�������� ������ �����:\n";
for (int i = 0; i < lines.size(); ++i) {
file2 << " " << std::setw(4) << (i + 1) << ". \"" << lines[i] << "\"\n";
}

file2 << "\n������ ����� ����� �������� �������� �����:\n";
file2 << " �����: " << porog << " ��������\n";
for (int i = 0; i < poroglines.size(); ++i) {
file2 << " " << std::setw(4) << (i + 1) << ". \"" << poroglines[i]
<< "\" (" << poroglines[i].length() << ")\n";
}

file2 << "\n������ ����� ����� ������ �������� �� \"_\":\n";
for (int i = 0; i < lineswospace.size(); ++i) {
file2 << " " << std::setw(4) << (i + 1) << ". \"" << lineswospace[i]
<< "\"\n";
}

file2 << "\n��������� ������ ��������� �����:\n";
file2 << "������� �����: " << word << "\n";
for (int i = 0; i < found.size(); ++i) {
file2 << " " << (i + 1) << ". " << found[i] << "\n";
}

file2 << "\n����� ���������� �������� ��� \"_\": " << allchars << "\n";

file2 << "\n������ ���� �����:\n";
for (int i = 0; i < lengthstr.size(); ++i) {
file2 << " " << std::setw(4) << (i + 1) << ". " << lengthstr[i] << "\n";
}
}
34 changes: 34 additions & 0 deletions sem2/OvsyannikovaVA/MINI_3/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
�������� ������ �����:
1. "Hello world"
2. "C++ programming is fun"
3. "Lambda expressions"
4. "STL algorithms"
5. "Short"
6. "A very long string just for testing purposes"

������ ����� ����� �������� �������� �����:
�����: 20 ��������
1. "C++ programming is fun" (22)
2. "A very long string just for testing purposes" (44)

������ ����� ����� ������ �������� �� "_":
1. "Hello_world"
2. "C++_programming_is_fun"
3. "Lambda_expressions"
4. "STL_algorithms"
5. "Short"
6. "A_very_long_string_just_for_testing_purposes"

��������� ������ ��������� �����:
������� �����: world
1. Hello world

����� ���������� �������� ��� "_": 114

������ ���� �����:
1. 11
2. 22
3. 18
4. 14
5. 5
6. 44