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; otherwise, arrange the characters A in the reverse order of the alphabetic. " I have problems only with the ordering of the characters A in the reverse order of the alphabetic c ++ PS The 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); int j = a.size(); char * writable = new char[a.size() + 1]; cout << "А : " << a << endl; cout << "B : " << b << endl; const char*str1 = a.c_str(); const char*str2 = b.c_str(); int count1[256] = { 0 }; int count2[256] = { 0 }; for (const char*pos = str1;*pos;++pos) ++count1[(unsigned char)*pos]; for (const char*pos = str2;*pos;++pos) ++count2[(unsigned char)*pos]; bool res = true; for (int i = 0;i < 256;++i) res = res && count1[i] == count2[i]; if (res == true) { 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; res = false; } else { /*Тут как раз не могу реализовать сортировку символов строки А в обратном алфавитному порядке*/ for (int i = 0; i < sizeof(writable) - 2;i++) { for (int j = 0; j < sizeof(writable) - 2 ;j++) { if (writable[j] < writable[j + 1]) { tmp = writable[j]; writable[j] = writable[j + 1]; writable[j + 1] = tmp; } } } cout << "A : " << writable; } system("pause"); return 0; }
sort- or is it not provided by the rules of the game? - Harry