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?
why reinterpret cast is considered dangerous?
What is a class in oop?
What are two types of polymorphism?
Give two or more real cenario of virtual function and vertual object
Templates mean
What is class and object in oops?
Why is polymorphism used?
Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
Get me an image implementation program.
Plese get me a perfect C++ program for railway/airway reservation with all details.
What is the highest level of cohesion?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
What is constructor overloading in oop?