1883. 删减
农夫约翰把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过 106106 的字符串 SS。
他希望从 SS 中删除子串 TT。
农夫约翰在 SS 中从头开始寻找子串 TT,一旦找到,就将它从 SS 中删除,然后再次从头开始寻找(而不是接着往下找)。
他重复这个操作直到 SS 中没有子串 TT 为止。
注意,删除一个子串 TT 可能会导致一个新的子串 TT 的出现。
请帮助约翰完成这些操作并输出最后的 SS。
输入格式
第一行包含字符串 SS。
第二行包含字符串 TT。
输出格式
输出操作完成后的 SS。
保证最终字符串 SS 不为空。
数据范围
SS 的长度不超过 106106,TT 的长度不超过 100100 且不超过 SS 的长度,字符串中只出现小写字母。
输入样例:
whatthemomooofun
moo
输出样例:
whatthefun
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string s, c, S;
cin >> s >> c;
int ls = s.size(), lc = c. size();
for(int i = 0; i < ls; i ++ ){
S += s[i];
if(S.size() >= lc && S.substr(S.size() - lc, lc) == c){
S.erase(S.begin() + S.size() - lc, S.end());
}
}
cout << S;
return 0;
}