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

来源:互联网 发布:mysql 最近一周 编辑:程序博客网 时间:2024/05/12 00:53

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

例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”。

提示:采用hash表

#define SIZE 256char* deleteCharInString(char *src, char *delStr) {int hash[SIZE] = { 0 };int i = 0;if (!src || !delStr) {return src;}//记录字符是否出现while (*delStr != '\0') {hash[*(delStr++)]++;}char result[SIZE] = { 0 };i = 0;while (*src != '\0') {if (!hash[*src]) {result[i++] = *src;}src++;}result[i] = '\0';return result;}


0 0
原创粉丝点击