`
kmplayer
  • 浏览: 499101 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

在字符串a中删除字符串b中存在的字符

 
阅读更多
1,实例代码:
#include<iostream>
using namespace std;

char hashTable[256];

void initHash(const char * b)
{
    while(*b!='\0')
        hashTable[*b++] = 1; //下标对应字符的ascii码。
}

void ProcessTheString(char * a)
{
    char * pFast;
    char * pSlow;
    pFast = pSlow = a; //实在是太nb了.
    while (*pFast!='\0')
    {
        if(!hashTable[*pFast])
            *pSlow++ = *pFast++;
        else
            pFast++;
    }
    *pSlow = '\0';
}

int main()
{
    char a[] = "They are Students.";
    char b[] = "aeiou";

    initHash(b);
    ProcessTheString(a);

    printf("%s", a);
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics