#include <iostream> #include <string> #include <windows.h> #include <cctype> #include…
- User
#include #include #include <windows.h> #include #include
using namespace std;
int main() { setlocale(LC_ALL, "Russian"); SetConsoleCP(1251); SetConsoleOutputCP(1251);
int temp1 = 0; int temp2 = 0;
int temp11 = 0; int temp22 = 0;
char we; char wr;
string text; ifstream file; file.open("C:\Users\chetc\source\repos\Bezopasnost2lab\Bezopasnost2lab\19var.txt"); getline(file, text);
int letterCounts[32] = { 0 }; // Массив для хранения количества каждой буквы int letterCounts1[27] = { 0 }; // Массив для хранения количества каждой буквы
// Преобразуем текст в нижний регистр для подсчета без учета регистра for (char& c : text) { c = tolower(c); }
// Перебираем каждый символ в тексте for (char c : text) { // Проверяем, является ли символ строчной русской буквой if (c >= 'а' && c <= 'я') { // Индекс в массиве рассчитывается как разница между символом и 'а' letterCounts[c - 'а']++; } }
for (char c : text) { // Проверяем, является ли символ строчной английской буквой if (c >= 'a' && c <= 'z') { // Индекс в массиве рассчитывается как разница между символом и 'а' letterCounts1[c - 'a']++; } }
cout « "Количество каждой русской буквы в тексте:\n"; // Выводим количество каждой буквы for (int i = 0; i < 32; i++) { // 'а' + i дает соответствующую букву char letter = 'а' + i; if (letterCounts[i] > 0) { cout « letter « ": " « letterCounts[i] « endl; } }
cout « "Количество каждой английской буквы в тексте:\n"; // Выводим количество каждой буквы for (int i = 0; i < 27; i++) { // 'а' + i дает соответствующую букву char letter = 'a' + i; if (letterCounts1[i] > 0) { cout « letter « ": " « letterCounts1[i] « endl; } }
temp1 = letterCounts[0]; temp11 = letterCounts1[0];
for (int i = 1; i < 32; i++) { if (letterCounts[i] > temp2) { wr = 'а' + i; temp1 = temp2; temp2 = letterCounts[i]; } }
for (int i = 1; i < 27; i++) { if (letterCounts1[i] > temp22) { we = 'a' + i; temp11 = temp22; temp22 = letterCounts1[i]; } }
if (temp2 > temp22) { cout « "Наибольшее - " « wr « ": " « temp2 « endl; } else { cout « "Наибольшее - " « we « ": " « temp22 « endl; temp2 = temp22; }
if (temp1 > temp11) { //cout « "2 наибольшее: " « temp1 « endl; } else { //cout « "2 наибольшее: " « temp11 « endl; temp1 = temp11; }
return 0; } напиши комментарии к каждой строке
- Assistant