輸入:兩個字符串,一個是源字符串,被刪除的。一個是”刪除字符串“
輸出:被刪除後的源字符串
#include <iostream>
#include <string.h>
using namespace std;
void DelChars(char *strsource,char *strdelete)
{
if((strsource==NULL)||(strdelete==NULL))
return;
int hash[128];
memset(hash,0,256);
while(*strdelete!='\0')
{
hash[*strdelete]=1;
strdelete++;
}
char *back,*head;
back=head=strsource;
while(*head!='\0')
{
if(hash[*head]!=1)
{
*back=*head;
back++;
}
head++;
}
*back='\0';
}
int main()
{
char src[30],str[10];
cin.getline(src,30);
cin.getline(str,10);
cout<<endl;
DelChars(src,str);
cout<<src<<endl;
return 0;
}