All pastes #2092643 Raw Edit

Anonymous

public text v1 · immutable
#2092643 ·published 2011-10-22 22:06 UTC
rendered paste body
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

void _generatePasswordForSize(char* pwd, int index, int size, string& keys)
{
	if (index == size)
	{
		cout << pwd << " ";
		return;
	}

	for (unsigned int i = 0; i < keys.size(); i++)
	{
		pwd[index] = keys[i];
		_generatePasswordForSize(pwd, index + 1, size, keys);
	}
}

void GeneratePassword(string& keys)
{
	char pwd[11];
	for (int i = 1; i < 10; i++)
	{
		memset(pwd, 0, 11);
		_generatePasswordForSize(pwd, 0, i, keys);
	}
}

int main ()
{
	int n;
	vector<string> dict;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		char in[80];
		scanf("%s", in);
		string input(in);
		dict.push_back(input);
	}

	// Generate bloom filters for each key
	int nKey;
	scanf("%d", &nKey);
	for (int i = 0; i < nKey; i++)
	{
		char in[26];
		scanf("%s", in);
		string key(in);
		cout << key;

		/*vector<bool> bloomFilter(26, false);

		for (unsigned int j = 0; j < key.size(); j++)
		{
			bloomFilter[key[j] - 'a'] = true;
		}
		
		vector<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.push_back(&dict[x]);
			}
		}
		
		if (results.size() == 0)
		{
			// It can't be none...
			//GeneratePassword(key);
			cerr << "NONE";

		}
		sort(results.begin(), results.end());
		for (unsigned int x = 0; x < results.size(); x++)
		{
			cerr << (*results[x]).c_str() << " ";
		}
		/*
		*/
		if (i != n-1)
			cerr << "\n";
	}
	return 0;
}