-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.cpp
56 lines (52 loc) · 1.18 KB
/
8.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
52
53
54
55
56
/*
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|).
Example 1:
Input:
string1 = "computer"
string2 = "cat"
Output: "ompuer"
Explanation: After removing characters(c, a, t)
from string1 we get "ompuer".
Input:
string1 = "occurrence"
string2 = "car"
Output: "ouene"
Explanation: After removing characters
(c, a, r) from string1 we get "ouene".
*/
#include<bits/stdc++.h>
using namespace std;
class Solution
{
public:
string removeChars(string string1, string string2)
{
for(int i=0;i<string1.size();i++)
{
for(int j=0;j<string2.size();j++)
{
if(string1[i]==string2[j])
{
string1.erase(string1.begin()+i);
i--;
}
}
}
return string1;
}
};
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;
}