Предмет: Информатика, автор: kirzovkirz

помогите пожалуйста исправить программу с++
Напишите программу, которая заменяет в символьной строке все буквы a на буквы b , буквы A на буквы B , буквы b на буквы a и буквы B на буквы A .

Входные данные
Входная строка содержит символы латинского алфавита, как строчные, так и заглавные.

Выходные данные
Программа должна вывести в первой строке получившуюся в результате обработки символьную строку, а во второй – количество выполненных замен.

Примеры
входные данные
aabbccAABBCC
выходные данные
bbaaccBBAACC
8
--------------------
#include < stdio.h >
#include < iostream >
#include < string >
using namespace std;

int main()
{
int i, d=0

string s;
cout << "Введите строку";
getline(cin,s);
for(int i=0;i
{
if(s[i]== 'A'){
s[i] = 'B';
d++;
}
else if(s[i]== 'a'){
s[i] = 'b';
d++;
}
else if(s[i]== 'B'){
s[i] = 'A';
d++;
}
else if(s[i]== 'b'){
s[i] = 'a';
d++;
}
}
cout< }


kirzovkirz: #include
#include
#include
using namespace std;

int main()
{
int i, d=0

string s;
cout << "Введите строку";
getline(cin,s);
for(int i=0;i
{
if(s[i]== 'A'){
s[i] = 'B';
d++;
}
else if(s[i]== 'a'){
s[i] = 'b';
d++;
}
else if(s[i]== 'B'){
s[i] = 'A';
d++;
}
else if(s[i]== 'b'){
s[i] = 'a';
d++;
}
}
cout< }
Аноним: а что сделать-то надо раз готовый код уже есть?
Hn94: Да у него он нихрена не работает)
Hn94: На заметку: перед getline() всегда делай перевод строки endl или же \n так как в ином случае у тебя getline считает пустую строку (\n)

Ответы

Автор ответа: Hn94
1

Ответ:

Объяснение:

#include <iostream>

#include <string>

using namespace std;

int main()

{

setlocale(LC_ALL, "ru");

int d = 0;

string s = "";

cout << "Введите строку:" << endl;

getline(cin, s);

for (int i = 0; i < s.length(); i++)

{

 if (s[i] == 'A')

 {

  s[i] = 'B';

  d++;

 }

 else if (s[i] == 'a')

 {

  s[i] = 'b';

  d++;

 }

 else if (s[i] == 'B')

 {

  s[i] = 'A';

  d++;

 }

 else if (s[i] == 'b')

 {

  s[i] = 'a';

  d++;

 }

}

cout << s << endl

 << d << endl;

}


kirzovkirz: Увидел комментарий, учту ошибки. Спасибо что помог
Похожие вопросы
Предмет: Английский язык, автор: maksimkavorono
Помогите перевести текст по английскому
When the twins Tim and Tom were born, their mother and father and grandparents were really very happy, but they were also a little puzzled. You see, Tim and Tom were born into a dark-haired Irish family. Their parents both had coal black hair. Their grandparents also used to have heads of thick black hair. Now, their grandparents’ hair was turning silver. In fact, all the uncles, aunts and cousins in the family had very dark thick black hair. In Ireland, people with black hair and dark eyes are called “black Irish,” and this is ofen a sign of beauty.Teir relatives, who visited them in the hospital, immediately thought that Tim and Tom were just cute as a button. But, everyone was at a loss as to why they had full heads of bright red hair. Tough there is no lack of redheads, or “gingers,” in Ireland, no one could think of a family member with red hair. It was clear that the twins had their father’s distinctive chin and nose. Also, from their first viewing, all the relatives commented on how the boys had their mother’s eyes and dimples. But, they also joked that the twins had been kissed by a leprechaun, and that was the reason for their bright red hair. Afer seeing the boys, their great uncle Bill went home to look through old photos. Tere, he discovered a picture of a distant relative: the sister of the twins’ great grandmother, Aunt Lizzie. Her picture was in black and white, but it was clear that her hair was lighter than her sister’s. No one can tell for sure if great, great Aunt Lizzie was a ginger, but the family was happy to say that the mystery was solved.
Предмет: Русский язык, автор: орёл2006