The task itself looks completely like this: "after one empty line, you are prompted to enter line A (input is done by pressing the Enter key), and then line B. After that, output the processed lines. If the lines consist of the same characters, remove the Latin characters from B and Russian letters; in other cases, arrange the characters A in the reverse order of the alphabetical "PS connection of other libraries is not considered
#include <iostream> #include <windows.h> #include <string> using namespace std; int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(LC_ALL, "Russian"); string a,b; cout << "Введите строку А : "; getline(cin,a); cout << "Введите строку B : "; getline(cin,b); cout << "А : " << a << endl; cout << "B : " << b << endl; if (a == b) { for (int unsigned i = 0; i < b.size();i++) { char ch = b[i]; if ((((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) || (((ch >= 'а') && (ch <= 'я')) || ((ch >= 'А') && (ch <= 'Я')))) { b.erase(i, 1); --i; } } cout << "B : " << b << endl; } else { /*Тут как раз не могу реализовать сортировку символов строки А в обратном алфавитному порядке*/ } system("pause"); return 0; }
a == bnot exactly the same thing.bmust be a permutationa, i.e. characters can be in different positions ("1a*"and"a*1"- consist of the same characters, buta != b). And it is not very clear what to do with characters of different registers. Should be CBAcba or cbaCBA or CcBbAa or cCbBaA? For the first option, it is enough to perform any sorting descending overa. - Drawn Raccoon