您的位置:首页 > 其它

编写算法,从字符串S中删除所有和字符串t相同的字符

2015-06-12 20:26 369 查看
/*编写算法,从字符串S中删除所有和字符串t相同的字符*/

#include<iostream>
#include<string>
using namespace std;

void move(string * S,int location);

void compare(string * S,string t)
{
int length_S=S->length();
int length_t=t.length();
for(int i=0;i<length_S;i++)
{
for(int j=0;j<length_t;j++)
{
if((*S)[i]==t[j])
{
move(S,i);
}

}

}
}

void move(string * S,int location)
{
int length_S=S->length();
for(int i=location;i<length_S;i++)
{
(*S)[i]=(*S)[i+1];
}
}

void print(string S)
{
cout<<S<<endl;
}

int main()
{
string S="ABCDEF";
string t="ABC";
compare(&S,t);
print(S);
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: