Составить программу в С++builder. По строковым типам данных. 1) Подсчитать, каких символов “*” или “%” больше и на сколько.

3 Июл 2020 в 19:42
164 +1
0
Ответы
1
include include

using namespace std;

int main() {
string str;
int count_star = 0;
int count_percent = 0;

cout << "Enter a string: ";
getline(cin, str);
for (int i = 0; i < str.length(); i++) {
if (str[i] == '*' || str[i] == '%') {
if (str[i] == '*') {
count_star++;
} else {
count_percent++;
}
}
}
if (count_star > count_percent) {
cout << "There are more '*' than '%' in the string by " << count_star - count_percent << " characters." << endl;
} else if (count_percent > count_star) {
cout << "There are more '%' than '*' in the string by " << count_percent - count_star << " characters." << endl;
} else {
cout << "The number of '*' and '%' characters is equal in the string." << endl;
}
return 0;

}

18 Апр 2024 в 10:49
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир