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?.

Answers were Sorted based on User's Feedback



Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / gopichandar

'e'and 'o'

Is This Answer Correct ?    9 Yes 3 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / jethvamohit

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "mohim";
string str1 = "mo";
remove(str, str1);
}
private static void remove(string str,string str1)
{
char[] abc;
abc = str.ToCharArray();
char[] bcd;
string str4 = "";
bcd = str1.ToCharArray();
for (int i = 0; i < bcd.Length; i++)
{
for (int j = 0; j < abc.Length; j++)
{
if (abc[j] != bcd[i])
{

str4 = str4 + abc[j];
}
}
abc = str4.ToCharArray();
str4 = "";
}
Console.Write(abc);
Console.ReadLine();

}
}
}

Is This Answer Correct ?    4 Yes 1 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / preeti

Lttle correction in above answer.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "mohim";
string str1 = "mo";
remove(str, str1);
}
private static void remove(string str,string str1)
{
char[] abc;
abc = str.ToCharArray();
char[] bcd;
string str4 = "";
bcd = str1.ToCharArray();
for (int i = 0; i < bcd.Length; i++)
{
for (int j = 0; j < abc.Length; j++)
{
if (abc[j] != bcd[i])
{

str4 = str4 + abc[j];
}
}
abc = str4.ToCharArray();
str4 = "";
}

str = "";
for (int j = 0; j < abc.Length; j++)
{

str = str + abc[j];

}

Console.Write("str : ");
Console.Write(str)
}
}
}

output will be
------------------------

str : hi

Is This Answer Correct ?    2 Yes 0 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / amadou

. static void Main(string[] args)
{
string x = "hello";
string y = "open";
string temp = "";
for (int i = 0; i < x.Length; i++)
{

if (!y.ToString().Contains(x[i]))
{
temp += x[i];

}
Console.WriteLine("temp={0}",
temp);
}
Console.Read();

Is This Answer Correct ?    3 Yes 1 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / sourabh bose

int countX=0;
int countY=0;
string tmp=x;
for(countX=1;countX<=x.lenth();countX++)
{
for(countY=1;countY<=y.length();countY++)
{
if x.substring(1,countX).Equels(y.substring(1,countY)
{
tmp=tmp.Replace(tmp.substring(1,countX),"");
}
}
}
x=tmp;

Is This Answer Correct ?    4 Yes 3 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / guest

public static void main(String[] args) {
String str_x = "hello";
String str_y = "open";

StringBuffer result = new StringBuffer();

for (int i=0; i<str_x.length();i++){
if (str_y.indexOf(str_x.charAt(i)) < 0)
result.append(str_x.charAt(i));
}

System.out.print(result);
}

Is This Answer Correct ?    5 Yes 4 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / skybeaver

static public string StupidQuestion(string x, string y)
{
StringBuilder sb = new StringBuilder();
Hashtable ht = new Hashtable();

// just one pass through y
foreach( char c in y.ToCharArray() )
if( !ht.Contains(c) )
ht.Add(c, c)

// just one pass thru x
foreach( char c in x.ToCharArray() )
if( !ht.Contains(c) )
sb.Append(c);

return sb.ToString();
}

Is This Answer Correct ?    2 Yes 2 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / vijay bhatia

string processString(string x, string y) {
string res = "";
int occuranceCount[26];
for(int i=0; i<26; i++) {
occuranceCount[i] = 0;
}
for(i=0; i<y.size(); i++) {
occuranceCount[y[i]-'a']++;
}
for(i=0; i<x.size(); i++) {
if (occuranceCount[x[i]-'a'] == 0) {
res += x[i];
}
}
return res;
}

Is This Answer Correct ?    0 Yes 0 No

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / 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

Given two strings like x=?hello? and y=?open?, remove any character from string x which is also us..

Answer / m@c

string x = "?hello?", y = "?open?";
char strm = '?';
for (int ictr = 0; ictr < y.Length; ictr++)
{
if (!strm.Equals(y[ictr]))
{
x=x.Replace(Convert.ToString(y[ictr]),"");
}

}
Response.Write(x);

Results will be <b>?hhl?</b>

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More OOPS Interview Questions

The type of variable a pointer points to must be the part of pointer's definition so that:

1 Answers   Infosys,


The company is a fake company asking for money of RS10000 while training and not offering a job after training. My humble request to you people not to attend Astersys interview

1 Answers   Astersys,


What are the four main oops concepts?

1 Answers  


Why is oop better than procedural?

0 Answers  


What is a scope resolution operator?

5 Answers   HP, IBS,






When is it necessary to use member-wise initialization list in C++?

2 Answers   Adobe,


me get an assignent n its question is this 1.creat a set as in math i.ea={1,2} 2.insert element in it3. delete element don,t repeat any element 4.union 5. intersection of two sets plz help me i always pray for u n send me at ayeshawzd@hotmail.com f u have c++ how to program 5th addition then it is the 10.9 question in 10th chapter exercise

1 Answers  


What is solid in oops?

0 Answers  


What are the different forms of polymorphism??

8 Answers   Mantaq, NUC, PCS,


what is the use of mutable key word

3 Answers   HCL,


Why do while loop is used?

0 Answers  


Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation

0 Answers   TCS,


Categories