C/C++

Задача по работе со строками на языке программировании c++

Дана фраза. Выяснить, сколько в ней прилагательных в единственном числе, т. е. слов, оканчивающихся на «-ый», «-ая» и «-ое»?
Но только для именительного падежа и под Windows
 #include  
#include
#include
#include
#include

using namespace std;

struct Word {
string word;
Word() = default;
Word(const string& word) : word(word) {}
string trim() {
word = trim_space();
word = trim_punct();
return word;
}
private:
string trim_space() {
word = regex_replace(word, regex(" +"), " ");
word.erase(0, word.find_first_not_of(" "));
word.erase(word.find_last_not_of(" ") + 1);
return word;
}
string trim_punct() {
return regex_replace(word, regex("[.?!)(,;:]"), "");
}
};

struct Adjective : public Word {
Adjective() = default;
Adjective(const string& word) : Word(word) {
this->word = trim();
}
bool is_singular_nominative_case()const {
if (word.length() > 3) {
auto ending = string{ word.end() - 2, word.end() };
for (const auto& item : singular_nominative_case) {
if (ending == item) {
return true;
}
}
}
return false;
}
private:
inline static const string singular_nominative_case[]{
"ый", "ий", "ая", "яя", "oe", "ee", "ой"
};
};

struct Parser {
string line;
Parser(const string& line) : line(line) {
split();
}
size_t adjectives_singular_count() {
size_t count = 0;
for (auto& token : tokens) {
Adjective adjective(token);
if (adjective.is_singular_nominative_case()) {
++count;
}
}
return count;
}
private:
vector tokens;
void split() {
istringstream iss(line);
string token;
while (iss >> token) {
tokens.emplace_back(move(token));
}
}
};

int main() {
system("chcp 1251 > nul");
cout
Мухаммад Шерматов
Мухаммад Шерматов
76 117
Лучший ответ
Куракин Петар Извините за такую просьбу, вы можете написать код попроще, который считает только количество слов, которые оканчиваются на «-ый», «-ая» и «-ое»?