-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path148.cpp
60 lines (51 loc) · 1.08 KB
/
148.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
57
58
59
60
// C++ program to remove duplicates, the order of
// characters is not maintained in this progress
#include <bits/stdc++.h>
#define NO_OF_CHAR 256
using namespace std;
int* getcountarray(string str2)
{
int* count = (int*)calloc(sizeof(int), NO_OF_CHAR);
for (int i = 0; i < str2.size(); i++)
{
count[str2[i]]++;
}
return count;
}
/* removeDirtyChars takes two
string as arguments: First
string (str1) is the one from
where function removes dirty
characters. Second string(str2)
is the string which contain
all dirty characters which need
to be removed from first
string */
string removeDirtyChars(string str1, string str2)
{
// str2 is the string
// which is to be removed
int* count = getcountarray(str2);
string res;
// ip_idx helps to keep
// track of the first string
int ip_idx = 0;
while (ip_idx < str1.size())
{
char temp = str1[ip_idx];
if (count[temp] == 0)
{
res.push_back(temp);
}
ip_idx++;
}
return res;
}
// Driver Code
int main()
{
string str1 = "geeksforgeeks";
string str2 = "mask";
// Function call
cout << removeDirtyChars(str1, str2) << endl;
}