在字符串中删除特定的字符

来源:互联网 发布:我的知鸟怎么没有首页 编辑:程序博客网 时间:2024/05/19 14:35

在字符串中删除特定的字符


问题描述

输入两个字符串;

输出从第一字符串中删除第二个字符串中所有的字符后的字符串。

问题示例

输入“google” 和 “abcdefg”;

输出“ool”

问题分析1

采用hashtable简化对第二个字符串查询的复杂性;

使用快慢指针来定位查询、删除的位置。

代码

char *DeleteCertainCharacter(char *A,char *B){    int Map[256];    memset(Map,0,sizeof(Map));    int i = 0;    while(B[i]!='\0')        Map[(int)B[i++]] = 1;    char *pFast = A,*pSlow = A;    while(*pFast != '\0'){        while(Map[*pFast] == 1){            pFast++;        }        *pSlow = *pFast;        pSlow++;        pFast++;    }    *pSlow = '\0';    return A;}

by:狼儿乖乖

time:2015/1/18 13:50:55

参考


  1. http://zhedahht.blog.163.com/blog/static/25411174200801931426484/ ↩

0 0
原创粉丝点击