The task is very simple: the input receives the number of received lines, and then the lines themselves. The output should be (through the gap) the number of vowels in these lines.
// Подсчет гласных в строке #include <iostream> #include <string> #include <algorithm> #include <conio.h> using namespace std; class count_predicate { public: bool operator()(const char& expr) { if ( expr == 'a' || expr == 'o' || expr == 'i' || expr == 'u' || expr == 'y' || expr == 'e' ) return true; return false; } }; int main() { int N; // Нужное количество строк cin >> N; string strs[N]; for (int i = 0; i < N; i++) getline(cin, strs[i]); for (int i = 0; i < N; i++) { int n = count_if(strs[i].begin(), strs[i].end(), count_predicate()); cout << n << " "; } return 0; } When instead of getline() I use the usual cin>> , then everything works, but the lines come across with spaces, so vowels are considered incorrect. Here, for some reason, getline() somehow "interrupts" cin from above, and reads the number of lines as another line, as I understood from the program test (but this is not accurate). Actually, why is this happening?
And yet, I have a feeling that I am solving a problem very clumsy, is there any more elegant solution?
I am especially confused by the number of checks in the predicate. If there is such a solution, it is possible without STL, I use it exclusively for educational purposes, consolidate, so to speak, the material that has been studied.