-
Notifications
You must be signed in to change notification settings - Fork 354
/
Copy pathremove_character.cpp
51 lines (47 loc) · 1.14 KB
/
remove_character.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Given two strings string1 and string2, remove those characters from first string(string1) which are present in second
string(string2). Both the strings are different and contain only lowercase characters.
NOTE: Size of first string is always greater than the size of second string( |string1| > |string2|).
*/
// Initial template for C++
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
bool isPresent(string string2, char ch)
{
for (int i = 0; i < string2.length(); i++)
{
if (string2[i] == ch)
{
return true;
}
}
return false;
}
string removeChars(string string1, string string2)
{
string res = "";
for (int i = 0; i < string1.length(); i++)
{
if (!isPresent(string2, string1[i]))
res += string1[i];
}
return res;
}
};
int main()
{
int t;
cin >> t;
while (t--)
{
string string1, string2;
cin >> string1;
cin >> string2;
Solution ob;
cout << ob.removeChars(string1, string2) << endl;
}
return 0;
}