现在的位置: 首页 > 综合 > 正文

程序员编程艺术:第二章、字符串是否包含问题

2015年07月23日 ⁄ 综合 ⁄ 共 459字 ⁄ 字号 评论关闭

原址http://blog.csdn.net/v_JULY_v/article/details/6347454

其中的HASH方法和BITMAP方法感觉很实用

// StringInclude.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
bool cmp()
{
	char* strOne = "ABCDEFGHLMNOPQRS";  
    char* strTwo = "DCGSRQPOMZ";  
	int bitmap = 0;
	
	while(*strOne)
	{
		bitmap |= 1 << (*strOne - 'A');
		strOne++;
	}
	
	while(*strTwo)
	{
		if ((bitmap & 1 << (*strTwo - 'A')) == 0)
			return false;

		strTwo++;
	}

	return true;
}
int main(int argc, char* argv[])
{

	printf("%s\n", cmp()?"yes":"no");
	return 0;
}

抱歉!评论已关闭.