Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.

Answer Posted / newpolaris

bool IsInStr(char ch, const std::string& B)
{
return std::string::npos != B.find(ch);
}

// act fuction
std::string remove_same_char(const std::string& A, const
std::string& B)
{
typedef std::string::const_iterator cstr_const_it;
cstr_const_it iCSTR = A.begin();

// FOR OPTIMIZATION NRVO IS NEEDED
// ? IS POSSIBLE?
std::string _rt;

while ( iCSTR != A.end() )
{
if (!IsInStr(*iCSTR,B)) _rt+=*iCSTR;

iCSTR++;
}

return _rt;
}

int main()
{
std::string x = "hello";
const std::string y = "open";
x = remove_same_char(x, y);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is encapsulation in oop?

601


What is polymorphism explain its types?

674


If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?

940


write a program that takes input in digits and display the result in words from 1 to 1000

1985


What is encapsulation selenium?

552






What is the difference between encapsulation and polymorphism?

589


What is oops and its features?

580


IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?

1575


What are the 5 oop principles?

594


What is encapsulation and abstraction? How are they implemented in C++?

632


write knight tour problem which is present in datastructure

2160


Why do we need oop?

658


What is inheritance in simple words?

623


What is polymorphism and why is it important?

556


What is multilevel inheritance?

721