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 graphics
write a program to find 2^n+1 ?
What is the purpose of polymorphism?
Where is pseudocode used?
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
What does and I oop and sksksk mean?
What is oops concept with example?
Is enum a class?
What is polymorphism explain?
Give two or more real cenario of virtual function and vertual object
What is the difference between abstraction and polymorphism?
What are the 5 oop principles?
What is destructor example?
Why do we use inheritance?
Why multiple inheritance is not allowed?