rendered paste body#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main ()
{
int n;
vector<string> dict;
cin >> n;
for (int i = 0; i < n; i++)
{
string input;
cin >> input;
dict.push_back(input);
}
// Generate bloom filters for each key
int nKey;
cin >> nKey;
for (int i = 0; i < nKey; i++)
{
string key;
cin >> key;
vector<bool> bloomFilter(26, false);
for (unsigned int j = 0; j < key.size(); j++)
{
bloomFilter[key[j] - 'a'] = true;
}
set<string*> results;
// Go over the dictionnary
for (unsigned int x = 0; x < dict.size(); x++)
{
bool isInFilter = true;
for (unsigned int y = 0; y < dict[x].size(); y++)
{
isInFilter &= bloomFilter[dict[x][y] -'a'];
}
if (isInFilter)
{
results.insert(&dict[x]);
}
}
if (results.size() == 0)
{
cout << "NONE";
}
for (set<string*>::iterator it = results.begin();
it != results.end();
it++)
{
cout << (*(*it)) << " ";
}
cout << endl;
}
}