输入两个字符串 从第一个字符串中删除第二个字符串中所包含的所有字符

#include 
#include 

using namespace std;

char* string_del_characters(char* const src, const char* const dest){
	int destlen = strlen(dest);
	int hash_table[256] = 0;
	char *p = src;
	int index = 0;
	for(int i = 0; i < destlen; ++i){
		hash_table[(int)dest[i]] = 1;
	}
	while(*p != '\0'){
		if(0 == hash_table[(int)* p]){
			src[index++] = *p;
		}
		p++;
	}
	src[index] = '\0';
	return src;
}

int main(int argc, int * argv[]){
	char src[1024];
	cin >> src;
	char dest[1024];
	cin >> dest;

	char* pResult = string_del_characters(src,dest);
	cout << pResult << endl; 
}

你可能感兴趣的:(算法题)