Александр Л
Ученик
(227)
1 год назад
#include <iostream>
#include <string>
#include <regex>
#include <clocale>
int main()
{
setlocale(LC_ALL, "Russian");
char s[500];
std::cin.getline(s, 500);
std::string str = s/* строка */, sres;
std::regex rgx{ "[А-Яа-яЁё\\d[:alpha:]']+" };
std::ssub_match smw, suf;
int i = 0;
for (std::sregex_iterator ib{ str.begin(), str.end(), rgx }, ie; ib != ie; ++ib, ++i)
{
if (0 == i % 2)
{
sres += ib->prefix();
smw = ib->operator[](0);
}
else
{
sres += ib->str();
sres += ib->prefix();
sres += smw;
smw = std::ssub_match{};
}
suf = ib->suffix();
}
if (smw.length() != 0)
{
sres += smw;
smw = std::ssub_match{};
}
std::cout << (sres += suf) << std::endl;
}