Найти и вывести через пробел в алфавитном порядке русские буквы. Как это возможно реализовать?
Вводим строку с клавиатуры строку с различными символами и находим среди них только русские символы и выводим их через проблем в алфавитном порядке. ВАЖНО! (строка может содержать любые символы кроме переноса строки, в том числе пробелы и символы табуляции)
P.S. Моя программа выводит все символы по порядку, а нужно только русские.
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <windows.h>
#include <locale>
char tolower_rus(char c)
{
return tolower
(
c,
std::locale("")
);
}
std::string string_tolower_rus(const std::string& str)
{
std::string res_str = str;
std::transform
(
str.begin(),
str.end(),
res_str.begin(),
tolower_rus
);
return res_str;
}
std::string foo(std::string str)
{
std::string newStr(str);
char temp1, temp2;
for (auto it = newStr.begin(); it != newStr.end(); it++)
{
if (*it == ' ')
{
newStr.erase(it);
}
}
for (auto it = str.begin(); it != str.end(); it++)
{
if (*it == ' ')
{
str.erase(it);
}
}
newStr = string_tolower_rus(newStr);
for (int i = 0; i < str.size(); i++)
{
for (int j = 0; j < str.size() - 1; j++)
{
if (newStr[j] > newStr[j + 1])
{
temp1 = str[j];
temp2 = newStr[j];
str[j] = str[j + 1];
newStr[j] = newStr[j + 1];
str[j + 1] = temp1;
newStr[j + 1] = temp2;
}
}
}
return str;
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
std::string str;
std::getline(std::cin, str);
str = foo(str);
for (auto x : str)
{
std::cout << x << " ";
}
return 0;
}