// 3 клавіатури вводиться текстовий рядок. 
// Скласти програму, яка підраховує кількість слів у тексті, 
// які закінчуються на голосну літеру, виводить на екран всі слова, 
// довжина яких менша п'яти символів, 
// видаляє всі слова, як містять хоча б одну латинську літеру
#include <iostream>
#include <locale>
#include <string>
#include <sstream>
#include <vector>
#include <Windows.h>
std::vector<char> vomelLetters = { 'а','е','є','и','і','ї','о','у','ю','я' };
//std::vector<char> vomelLetters = { (char)'а',(char)'е',(char)'є',(char)'и',(char)'і',(char)'ї',(char)'о',(char)'у',(char)'ю',(char)'я' };
std::string delimiters = " ,-";
std::vector<std::string> split(const std::string, const std::string);
bool IsVomLetters(char);
size_t WordsCount(std::vector<std::string>);
void PrintVector(std::vector<std::string>);
//bool IsDelim(char);
int main()
{
    std::cout << "Input Line" << std::endl;
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    //SetConsoleCP(CP_UTF8);
    //SetConsoleOutputCP(CP_UTF8);
    std::string inputline;
    std::getline(std::cin, inputline);
    std::vector<std::string> wordsArray = split(inputline, delimiters);
        
    PrintVector(wordsArray);
    std::cout << "\n1. The number of words in the text that end with a vowel = " << WordsCount(wordsArray) << std::endl;
    std::cout << "2. All words whose length is less than five characters = " << std::endl;
    //
    for (size_t i = 0; i < wordsArray.size(); i++)
    {
        if (wordsArray[i].size() < 5)
            std::cout << " " << i << "\t" << wordsArray[i] << std::endl;
    }
}
size_t WordsCount(std::vector<std::string> vwords)
{
    char ch;
    //bool b = false;
    size_t count = 0;
    for (size_t i = 0; i < vwords.size(); i++)
    {
        ch = vwords[i].back();
        if ( IsVomLetters( ch ) )
        {
            //std::cout << "w[" << i << "] " << vwords[i] << " " << ch << std::endl;
            count++;
        }
    }
    return count;
}
bool IsVomLetters(char ch)
{
    for (size_t i = 0; i < vomelLetters.size(); i++)
    {
        if (vomelLetters[i] == ch)
            return true;
    }
    return false;
}
std::vector<std::string> split(const std::string str, std::string delim)
{
    std::vector<std::string> wordVector;
    std::string line = str;
    std::size_t prev = 0, pos;
    while ((pos = line.find_first_of(delim, prev)) != std::string::npos)
    {
        if (pos > prev)
            wordVector.push_back(line.substr(prev, pos - prev));
        prev = pos + 1;
    }
    if (prev < line.length())
        wordVector.push_back(line.substr(prev, std::string::npos));
    return wordVector;
}
void PrintVector(std::vector<std::string> v)
{
    for (size_t i = 0; i < v.size(); i++)
    {
        std::cout << "[" << i << "] = " << v[i] << '\t';
    }
    std::cout << "\n";
}