-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_common_character.cpp
57 lines (33 loc) · 883 Bytes
/
remove_common_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
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
string concatenetedString(string s1, string s2)
{
string res = ""; // result
// store all characters of s2 in map
unordered_map<char, int> m;
for (int i = 0; i < s2.size(); i++)
m[s2[i]] = 1;
// Find characters of s1 that are not
// present in s2 and append to result
for (int i = 0; i < s1.size(); i++) {
if (m.find(s1[i]) == m.end())
res += s1[i];
else
m[s1[i]] = 2;
}
// Find characters of s2 that are not
// present in s1.
for (int i = 0; i < s2.size(); i++)
if (m[s2[i]] == 1)
res += s2[i];
return res;
}
/* Driver program */
int main()
{
string s1 = "abcd";
string s2 = "cdefg";
cout << concatenetedString(s1, s2);
return 0;
}
/*abefg*/