#include <iostream>
#include <string>
#include <conio.h>
#define ESC 27
using namespace std;
int main() {
char ch;
int sum = 0;
do {
ch = _getch();
if (ch == ESC) {
cout << "Output of the program:\n" << sum;
putchar('\n');
} else {
cout << ch;
sum += (int)ch;
putchar('\n');
}
} while (ch != ESC);
system("pause");
return 0;
}
Объяснение:
#include <iostream>
#include <string>
#include <algorithm>
#include <Windows.h>
using namespace std;
bool check_alphabet(char symbol) {
string alphabet = "";
for (size_t j = 0; j < alphabet.size(); j++)
{
if (alphabet[j] == symbol) {
return true;
}
}
return false;
}
pair<int,string> erase_counter_char_in_str_not_latin(string str) {
int i = 0;
int count = 0;
while (i <= str.size() - 1) {
if (not (check_alphabet(toupper(str[i] {
str.erase(str.begin() + i);
count++;
i--; // раз удалили, то нужно вернуться назад на один: i~45m -> i5~m (i уже идёт на следующий)
}
i++;
}
return make_pair(count, str);
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
string str;
cout << "Введите строку: " << endl;
cin >> str;
pair<int,string> pair_count_str = erase_counter_char_in_str_not_latin(str);
cout << endl << "Удалено: " << pair_count_str.first << endl;
cout << "Конечная строка: " << pair_count_str.second;
}