题目要求如下:
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
ab
Sample Output
a
ab
题目大致要求:W串为可疑串,P为用户输入的字符串,
且包含W串,即W串为P的子串,从P中找出W串,并删除(W,P均为小写字母)
C++程序代码如下:
#include<iostream>
#include<cstring>
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()); //删除掉S2中出现的可疑串
}
cout<<s2<<endl;
}
return 0;
}
运行截图:
08-23
04-07
04-25
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交