在字符串中删除另一个字符串中出现的字符
2013-04-19 11:39
337 查看
#include<iostream> #include<algorithm> #include<string.h> #include<sstream> #include<cstdio> using namespace std; int hashtable[256]; void initTable(char *substr) { memset(hashtable,0,sizeof(hashtable));//#include<string.h> char *p = substr; while(*p!='\0') { hashtable[*p] = 1; p++; } p = NULL; } char *Delete(char *source, char *substr) { char *fast = source; char *slow = source; while(*fast != '\0') { if(hashtable[*fast] != 1) { *slow = *fast; slow++; } fast++; } *slow = '\0'; return source; } int main() { char source[] = "Buyer's remorse occurs when a person purchases something on a whim, \ only to regret the purchase later. Similarly, a woman who is attracted \ to you may be pushed or, on her own, go too far too soon. While in \ the moment she may indulge in her attraction and sexual arousal) only \ to regret her feelings or actions later. Assuming you want to reach the \ seduction phase, buyer's remorse is something you want to avoid at all costs."; char substr[] = "ABCDEFGHIGKLMNOPQRSTUVWXYZ"; initTable(substr);//初始化table数组 cout<<Delete(source,substr)<<endl; getchar(); return 0; }
相关文章推荐
- 小米面试题 从一个字符串中删除在另一个字符串中出现的字符
- 【剑指offer】删除在另一个字符串中出现的字符
- 在字符串中删除另一个字符串中出现的字符
- 在一个字符串中删除指定的字符 & 删除字符串中所有出现在另一个字符数组中的字符
- 《剑指Offer》:删除在另一个字符串中出现的字符
- 在字符串中删除另一个字符串中出现的字符
- (面试题)删除在另一个字符串中出现的字符
- 从一个字符串中删除另一个字符串中出现的字符
- 从一个字符串中删除另一个字符串中出现过的字符
- 从一个字符串中删除另一个字符串中出现的字符
- 【剑指offer】删除在另一个字符串中出现的字符
- 【剑指offer】之删除在另一个字符串中出现的字符
- 从一个字符串中删除另一个字符串中出现过的字符
- 删除字符串中出现次数最少的字符
- 在S1字符串中删除S2字符串出现过的任意字符
- 华为在线编程系列-删除字符串中出现次数最少的字符
- java中统计一个字符串串在另一个字符串中出现的次数
- 华为OJ——删除字符串中出现次数最少的字符
- 【C编程练习】华为2013校园招聘机试题目题4:删除一个字符串中出现次数最少的字符,函数原型为:char * delChar(char *s,int iLen)
- 删除字符串中出现次数最少的字符