# Which are in? [6 kyu]
[Which are in?](https://www.codewars.com/kata/550554fd08b86f84fe000a58)
6 kyu
## Solution
```cpp=
/**
*** Author: R-CO
*** E-Mail: daniel1820kobe@gmail.com
*** Date: 2020-07-22
**/
#include <algorithm>
#include <cstdlib>
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <vector>
using std::vector;
struct TestCaseStruct {
struct Input {
vector<string> array1;
vector<string> array2;
} input;
vector<string> expected_output;
};
class WhichAreIn {
public:
static std::vector<std::string> inArray(std::vector<std::string> &array1,
std::vector<std::string> &array2) {
vector<string> output;
for (const auto a1 : array1) {
for (const auto a2 : array2) {
if (a2.find(a1, 0) != string::npos) {
output.emplace_back(a1);
break;
}
}
}
std::sort(output.begin(), output.end());
return output;
}
};
int main(int argc, char *argv[]) {
/*
#Example 1 : a1 = ["arp", "live", "strong"]
a2 = [ "lively", "alive", "harp", "sharp", "armstrong" ]
returns["arp", "live", "strong"]
#Example 2 : a1 = ["tarp", "mice", "bull"]
a2 = [ "lively", "alive", "harp", "sharp", "armstrong" ]
returns[]
*/
TestCaseStruct test_cases[] = {
{{{"arp", "live", "strong"},
{"lively", "alive", "harp", "sharp", "armstrong"}},
{"arp", "live", "strong"}},
{{{"tarp", "mice", "bull"},
{"lively", "alive", "harp", "sharp", "armstrong"}},
{}}};
WhichAreIn solution;
int index = 0;
for (auto &test_case : test_cases) {
const auto &output =
solution.inArray(test_case.input.array1, test_case.input.array2);
if (output.size() == test_case.expected_output.size() && std::equal(output.begin(), output.end(),
test_case.expected_output.begin())) {
cout << "test case \"" << index++ << "\" is pass." << std::endl;
} else {
cout << "test case \"" << index++ << "\" is fail." << std::endl;
}
}
return EXIT_SUCCESS;
}
```
## Result
PASS
###### tags: `CodeWars` `C++`