-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique_names.cpp
58 lines (51 loc) · 1.41 KB
/
unique_names.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
#include <iostream>
#include <vector>
std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
{
std::vector<std::string> resulting_vector;
bool found=false;
for (unsigned int i=0; i<names1.size(); i++)
{
for (unsigned int j=0; j<resulting_vector.size(); j++)
{
if (resulting_vector[j]==names1[i])
{
found=true;
}
}
if (!found)
{
resulting_vector.push_back(names1[i]);
}
found=false;
}
found=false;
for (unsigned int i=0; i<names2.size(); i++)
{
for (unsigned int j=0; j<resulting_vector.size(); j++)
{
if (resulting_vector[j]==names2[i])
{
found=true;
}
}
if (!found)
{
resulting_vector.push_back(names2[i]);
}
found=false;
}
return resulting_vector;
}
#ifndef RunTests
int main()
{
std::vector<std::string> names1 = {"Emma", "Ava", "Emma", "Olivia", "Ava"};
std::vector<std::string> names2 = {"Olivia", "Sophia", "Emma", "Sophia"};
std::vector<std::string> result = unique_names(names1, names2);
for(auto element : result)
{
std::cout << element << ' '; // should print Ava Emma Olivia Sophia
}
}
#endif