Exemple #1
0
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	int n,m;
	long long val;
	int len;
	long long seed=13131313;
	long long base=1;
	bool ok;

	myh.init();

	scanf("%d %d",&n,&m);

	while(n--)
	{
		scanf("%s",s);
		myh.insert(myh.hash(s));
	}

	while(m--)
	{
		base=1;
		ok=0;
		scanf("%s",s);
		val=myh.hash(s);
		len=strlen(s);

		for(int i=len-1;i>=0;--i)
		{
			for(int j=0;j<3;++j)
				if(j!=s[i]-'a')
					if(myh.match(((val+base*(j-(s[i]-'a'))%MOD+MOD)%MOD)))
					{
						ok=1;
						break;
					}

			if(ok)
				break;

			base=(base*seed)%MOD;
		}

		if(ok)
			puts("YES");
		else
			puts("NO");
	}
	
	return 0;
}
Exemple #2
0
/*----------------------------------------------------------------------
 * Get the internal list for a specified key.
 * Allocate it if not already done.
  -----------------------------------------------------------------------*/
static HashMapKeyNode HashMap_GetHashMapKeyNode(HashMap map, HashMapKey key, ThotBool create)
{
  int keyval;
  if(map == NULL || key == NULL || map->nodes == NULL)
    return NULL;
  keyval = (map->hash(key))%map->nbNodes;
  if (map->nodes[keyval] == NULL && create)
    map->nodes[keyval] = HashMap_CreateHashMapKeyNode(map);
  return map->nodes[keyval];
}
Exemple #3
0
/*----------------------------------------------------------------------
 * Dump the content of a hashmap.
  -----------------------------------------------------------------------*/
void HashMap_Dump (HashMap map, ThotBool isKeyString)
{
  int            i;
  HashMapKeyNode keynode;
  HashMapNode    node;
  
  printf ("Dump of hashmap %p\n", map);
  if (map)
    {
      printf("  destroyElement : %p\n", map->destroyElement);
      printf("  destroyKey     : %p\n", map->destroyKey);
      printf("  hash           : %p\n", map->hash);
      printf("  compare        : %p\n", map->compare);
      printf("  nodes          : %p\n", map->nodes);
      printf("  nbNodes        : %d\n", map->nbNodes);
      for (i = 0; i<map->nbNodes; i++)
        {
          keynode = map->nodes[i];
          if (keynode)
            {
              printf("  [%02d] %p (%p -> %p)\n", i,  keynode, keynode->first, keynode->last);
              node = (HashMapNode) keynode->first;
              while (node!=NULL)
                {
                  if(isKeyString)
                    printf("      (%p>>) %p (>>%p) : %p %s  (%d) - %p\n", node->prev, 
                                        node, node->next,
                                        node->key, (char*)node->key, 
                                        map->hash(node->key), node->elem);
                  else
                    printf("      (%p>>) %p (>>%p) : %p (%d) - %p\n", node->prev, 
                                        node, node->next,
                                        node->key, map->hash(node->key), node->elem);
                  node = node->next;
                }
            }
        }
    }
}
Exemple #4
0
/*----------------------------------------------------------------------
  -----------------------------------------------------------------------*/
static HashMapNode HashMapIterator_GetNext(ForwardIterator iter)
{
  HashMap map = (HashMap) iter->container;
  HashMapNode node = (HashMapNode) iter->currentNode;
  if (node->next!=NULL)
  {
    return node->next;
  }
  else
  {
    int i = (map->hash(node->key)%map->nbNodes)+1;
    for (; i< map->nbNodes; i++)
    {
      if (map->nodes[i] != NULL)
        {
          if (map->nodes[i]->first != NULL)
            return (HashMapNode)map->nodes[i]->first;
        }
    }
  }
  return NULL;
}