Discover a world of knowledge and community-driven answers at IDNLearn.com today. Our experts are ready to provide prompt and detailed answers to any questions you may have.
Sagot :
Using the knowledge in computational language in C++ it is possible to write a code that write a function so that the given string s consisting of n characters returns any string
Writting in C++ code:
#include <iostream>
#include <string>
using namespace std;
string solution(string &s)
{
//length of string
int n=s.size();
//index of string
int i=0;
while(i<n-1)
{
if(s[i]=='A')
{
if(s[i+1]=='B')
{
s=s.substr(0,i) + s.substr(i+2); i=0;
}
else
i++;
}
else if(s[i]=='B')
{
if(s[i+1]=='A')
{
s=s.substr(0,i) + s.substr(i+2); i=0;
}
else
i++;
}
else if(s[i]=='C')
{
if(s[i+1]=='D')
{
s=s.substr(0,i) + s.substr(i+2);
i=0;
}
else
i++;
}
else if(s[i]=='D')
{
if(s[i+1]=='C')
{
s=s.substr(0,i) + s.substr(i+2);
i=0;
} else
i++;
}
n=s.size();
}
return s;
}
int main() {
//Input string
string s="ACBDACBD";
solution(s);
//final output;
if(s=="")
cout<<"Empty String";
else
cout<<s;
return 0;
}
See more about C++ code at brainly.com/question/19705654
#SPJ1


We greatly appreciate every question and answer you provide. Keep engaging and finding the best solutions. This community is the perfect place to learn and grow together. Your search for answers ends at IDNLearn.com. Thanks for visiting, and we look forward to helping you again soon.