Files
dz5/1.cpp
2024-11-19 20:50:48 +03:00

113 lines
2.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
#include <fstream>
#include <cctype>
#include <limits>
using namespace std;
int gcdDivision(int a, int b) {
while (b != 0) {
int remainder = a % b;
a = b;
b = remainder;
}
return a;
}
int gcdSubtraction(int a, int b) {
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
return a;
}
int z1(int a, int b, int method) {
switch (method) {
case 1:
return gcdDivision(a, b);
case 2:
return gcdSubtraction(a, b);
default:
cout << "Некорректный выбор метода. Выберите 1 или 2." << endl;
return -1;
}
}
void findLeastFrequentVowel(const string& filePath) {
ifstream file(filePath);
if (!file) {
cerr << "Не удалось открыть файл." << endl;
return;
}
int counts[6] = { 0 }; // Счётчики для гласных: a, e, i, o, u, y
char vowels[] = { 'a', 'e', 'i', 'o', 'u', 'y' };
char ch;
while (file >> noskipws >> ch) {
ch = tolower(ch);
for (int i = 0; i < 6; ++i) {
if (ch == vowels[i]) {
++counts[i];
break;
}
}
}
file.close();
int minCount = numeric_limits<int>::max();
char leastVowel = '\0';
for (int i = 0; i < 6; ++i) {
if (counts[i] > 0 && counts[i] < minCount) {
minCount = counts[i];
leastVowel = vowels[i];
}
}
if (leastVowel) {
cout << "Наименее часто встречающаяся гласная: " << leastVowel
<< " (" << minCount << " раз)" << endl;
}
else {
cout << "В файле нет гласных букв." << endl;
}
}
void z3() {
string filePath;
filePath = "txt.txt";
findLeastFrequentVowel(filePath);
}
void z1launcher() {
int a, b, method;
cout << "Введите два положительных целых числа: ";
if (!(cin >> a >> b) || a <= 0 || b <= 0) {
cout << "Ошибка: ввод должен быть положительными целыми числами." << endl;
return;
}
cout << "Выберите метод:\n1 - Деление\n2 - Вычитание\nВаш выбор: ";
if (!(cin >> method) || (method != 1 && method != 2)) {
cout << "Ошибка: некорректный выбор метода. Введите 1 или 2." << endl;
return;
}
int result = z1(a, b, method);
if (result != -1) {
cout << "НОД = " << result << endl;
}
}
int main() {
setlocale(LC_ALL, "");
/*z1launcher();*/
z3();
return 0;
}