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/DurovaAV/Homework3/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
114 changes: 114 additions & 0 deletions sem2/DurovaAV/Homework3/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>

bool isVowel(char c) {
char lower = std::tolower(static_cast<unsigned char>(c));
return (lower == 'a' || lower == 'e' || lower == 'i' ||
lower == 'o' || lower == 'u' || lower == 'y');
}

int main() {
std::ifstream inFile("input.txt");
if (!inFile.is_open()) {
std::cerr << "Error: cannot open input.txt" << std::endl;
return 1;
}

std::vector<std::string> lines;
std::string line;

while (std::getline(inFile, line)) {
lines.push_back(line);
}
inFile.close();

int porog;
std::cout << "Enter length porog: ";
std::cin >> porog;

//�������� ����� ������ ������ (������ �� ��������)
auto removeShort = [porog](const std::string& s) {
return static_cast<int>(s.length()) < porog;
};
std::vector<std::string> afterRemove = lines;
afterRemove.erase(std::remove_if(afterRemove.begin(), afterRemove.end(), removeShort),
afterRemove.end());

//�������� ������� �� ������ ������
std::vector<std::string> afterProcess = afterRemove;
for (auto& str : afterProcess) {
str.erase(std::remove_if(str.begin(), str.end(),
[](char c) { return isVowel(c); }),
str.end());
}

//����� ������ � �������� ������ (������ �� ������)
std::string searchWord;
std::cout << "Enter word to search: ";
std::cin >> searchWord;
auto searchLambda = [&searchWord](const std::string& s) {
return s.find(searchWord) != std::string::npos;
};
auto it = std::find_if(afterProcess.begin(), afterProcess.end(), searchLambda);
std::string searchResult = (it != afterProcess.end()) ? *it : "Not found";

//������� ������ ���������� ��������
int totalChars = 0;
for (const auto& str : afterProcess) {
for (char c : str) {
if (c != '_') {
++totalChars;
}
}
}

//�������� ������� ���� �����
std::vector<int> lengths;
for (const auto& str : afterProcess) {
lengths.push_back(static_cast<int>(str.length()));
}

//����� � output.txt
std::ofstream outFile("output.txt");
if (!outFile.is_open()) {
std::cerr << "Error: cannot create output.txt" << std::endl;
return 1;
}

outFile << "*+- Original lines -+*\n";
for (const auto& l : lines) {
outFile << l << "\n";
}

outFile << "\n*+- After removing short lines (porog = " << porog << ") -+*\n";
for (const auto& l : afterRemove) {
outFile << l << "\n";
}

outFile << "\n*+- After removing vowels -+*\n";
for (const auto& l : afterProcess) {
outFile << l << "\n";
}

outFile << "\n*+- Search result for \"" << searchWord << "\" -+*\n";
outFile << searchResult << "\n";

outFile << "\n*+- Total characters (excluding '_') -+*\n";
outFile << totalChars << "\n";

outFile << "\n*+- Lengths of strings -+*\n";
for (int len : lengths) {
outFile << len << " ";
}
outFile << "\n";

outFile.close();

std::cout << "\nProcessing completed! Check output.txt" << std::endl;

return 0;
}
32 changes: 32 additions & 0 deletions sem2/DurovaAV/Homework3/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
*+- Original lines -+*
Hello world
C++ programming is fun
Lambda expressions
STL algorithms
Short
A very long string just for testing purposes

*+- After removing short lines (porog = 5) -+*
Hello world
C++ programming is fun
Lambda expressions
STL algorithms
Short
A very long string just for testing purposes

*+- After removing vowels -+*
Hll wrld
C++ prgrmmng s fn
Lmbd xprssns
STL lgrthms
Shrt
vr lng strng jst fr tstng prpss

*+- Search result for "fn" -+*
C++ prgrmmng s fn

*+- Total characters (excluding '_') -+*
84

*+- Lengths of strings -+*
8 17 12 11 4 32