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
program for insertion ,deletion,sorting in double link list
What is multilevel inheritance?
Why is abstraction used?
What is oops?what is its use in software engineering?
How do you define a class in oop?
What is polymorphism what are the different types of polymorphism?
What is a superclass in oop?
What are two types of polymorphism?
Can we create object of abstract class?
#include
What is class and object with example?
Will I be able to get a picture in D drive to the c++ program? If so, help me out?
What are the three parts of a simple empty class?
What is encapsulation in oop?
Can bst contain duplicates?