好儿郎-志在四方
2015-11-13 04:54
采纳率: 100%
浏览 1.8k

ACM编程题,找出敏感词串,并删除,要求时间和空间效率很高,我写的程序通不过,

Censor
frog is now a editor to censor so-called sensitive words (敏感词).

She has a long text p. Her job is relatively simple -- just to find the first occurence of sensitive word w and remove it.

frog repeats over and over again. Help her do the tedious work.

Input
The input consists of multiple tests. For each test:

The first line contains 1 string w. The second line contains 1 string p.

(1≤length of w,p≤5⋅106, w,p consists of only lowercase letter)

Output
For each test, write 1 string which denotes the censored text.

Sample Input
abc
aaabcbc
b
bbb
abc
abSample Output
a

ab

    上面是题目,大致要求:
    W串是可疑串,P是输入串,在P中将出现的W串删除,然后输出P串;
    下面是我写的代码:
    #include<iostream>

#include
using namespace std;

int main()
{
string s1,s2; //s1用于做可疑串,s2用于做输入串
while(cin>>s1)
{
cin>>s2;

    while(-1!=s2.find(s1))  //s2字符串中存在可疑串 
    {

        s2.erase(s2.find(s1),s1.size());
    }
    cout<<s2<<endl;
}

return 0;

}
图片说明
求大神编写一个C++程序,运行时间很低的程序,谢谢各位大牛了;

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题