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
What is encapsulation in oop?
What is polymorphism explain its types?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
write a program that takes input in digits and display the result in words from 1 to 1000
What is encapsulation selenium?
What is the difference between encapsulation and polymorphism?
What is oops and its features?
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?
What are the 5 oop principles?
What is encapsulation and abstraction? How are they implemented in C++?
write knight tour problem which is present in datastructure
Why do we need oop?
What is inheritance in simple words?
What is polymorphism and why is it important?
What is multilevel inheritance?