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


Please Help Members By Posting Answers For Below Questions

What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?

1880


What is inheritance in simple words?

804


can inline function declare in private part of class?

3953


What is a class and object?

779


write a C++ program for booking using constructor and destructor.

2245


What do you mean by abstraction?

802


What is the difference between a constructor and a destructor?

838


What is difference between inheritance and polymorphism?

762


Why is oop useful?

805


What is pointer in oop?

719


What is the fundamental idea of oop?

837


What are two types of polymorphism?

799


What is encapsulation process?

779


What is polymorphism and why is it important?

755


What is abstraction oop?

815