#include <iostream>
#include <sstream>
#include <unordered_set>
#include <vector>
#include <string>
#include <iterator>

std::istringstream tokens_in(
R"(00sdfdsf
ahdadsg
angel
ksjflsjdf
green
green000
carrot
)"
);

std::istringstream dict_in(
R"(angel
carrot
green
kitten
zoo
)"
);

using dictionary_type = std::unordered_set<std::string>;
dictionary_type read_dictionary(std::istream& is)
{
    using iter_type = std::istream_iterator<std::string>;
    return dictionary_type(iter_type(is), iter_type());
}

std::vector<std::string> filter(std::istream& token_stream, const dictionary_type& dictionary)
{
    std::vector<std::string> filtered_tokens;

    std::string token;
    while (token_stream >> token)
        if (dictionary.count(token))
            filtered_tokens.push_back(token);

    return filtered_tokens;
}


int main()
{
    auto filtered = filter(tokens_in, read_dictionary(dict_in));

    for (auto& token : filtered)
        std::cout << token << '\n';
}