删除模式串中出现的字符,如“welcome to asted”,模式串为“aeiou”那么得到的是“wlcm t std”。
#include<iostream>
#include<cstring>
using namespace std;
char *re(char *str,char *model)
{
if(str==NULL||model==NULL)
return NULL;
int Hash[26]={0};
for(int i=0;i<strlen(model);i++)
{
++Hash[model[i]-'a'];
}
char *address=str;
int index=0;
for(int i=0;i<strlen(str);i++)
{
if(str[i]==' '|| Hash[str[i]-'a']==0 )
{
str[index]=str[i];
index++;
}
}
str[index]='\0';
return address;
//
}
int main()
{
char str[]="welcome to asted";
char model[]="aeiou";
cout<<re(str,model)<<endl;
}
时间复杂度为O(n),空间复杂度为O(1)。