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 are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
What is inheritance in simple words?
can inline function declare in private part of class?
What is a class and object?
write a C++ program for booking using constructor and destructor.
What do you mean by abstraction?
What is the difference between a constructor and a destructor?
What is difference between inheritance and polymorphism?
Why is oop useful?
What is pointer in oop?
What is the fundamental idea of oop?
What are two types of polymorphism?
What is encapsulation process?
What is polymorphism and why is it important?
What is abstraction oop?