Description
Censor
frog is now a editor to censor so-called sensitive words (敏感词).
She has a long text p p. Her job is relatively simple -- just to find the first occurence of sensitive word w 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 1 string w w. The second line contains 1 1 string p p.
( 1≤length of w,p≤5⋅106 1≤length of w,p≤5⋅106, w,p w,p consists of only lowercase letter)
Output
For each test, write 1 1 string which denotes the censored text.
Sample Input
abc
aaabcbc
b
bbb
abc
ab
Sample Output
a
ab
/*头文件模板*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <typeinfo>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define pb push_back
#define mp make_pair
#define mem(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define FIN freopen("input.txt", "r", stdin)
#define FOUT freopen("output.txt", "w", stdout)
typedef long long LL;
typedef pair<int, int > PII;
typedef pair<int, string> PIS;
typedef pair<LL, LL>PLL;
typedef unsigned long long uLL;
template<typename T>
void print (T* p, T* q, string Gap = " ", bool flag = false) {
int d = p < q ? 1 : -1;
while (p != q) {
if (flag) cout << Gap[0] << *p << Gap[1];
else cout << *p;
p += d;
if (p != q && !flag) cout << Gap;
}
cout << endl;
}
template<typename T>
void print (const T &a, string bes = "") {
int len = bes.length();
if (len >= 2) cout << bes[0] << a << bes[1] << endl;
else cout << a << endl;
}
template<typename T>
void debug (T* p, T* q, string Gap = " ", bool flag = false) {
int d = p < q ? 1 : -1;
cout << "Debug out : ";
while (p != q) {
if (flag) cout << Gap[0] << *p << Gap[1];
else cout << *p;
p += d;
if (p != q && !flag) cout << Gap;
}
cout << endl;
}
template<typename T>
void debug (const T &a, string bes = "") {
int len = bes.length();
cout << "Debug out : ";
if (len >= 2) cout << bes[0] << a << bes[1] << endl;
else cout << a << endl;
}
void IO_Init() {
ios::sync_with_stdio (false);
}
LL LLabs (const LL a) {
return a >= 0 ? a : -a;
}
const double PI = 3.1415926535898;
const double eps = 1e-10;
const int MAXM = 1e5 + 5;
const int MAXN = 5e6 + 5;
const int INF = 0x3f3f3f3f;
/*头文件模板*/
char a[MAXN], b[MAXN], L[MAXN];
int nexts[MAXN];
struct o {
char c;
int l;
o() {}
o (char c, int l) : c (c), l (l) {}
};
void getNextval (char *p) {
int plen = strlen (p);
int k = nexts[0] = -1;
int j = 0;
while (j < plen - 1) {
if (k == -1 || p[j] == p[k]) {
j++;
k++;
if (p[j] != p[k]) {
nexts[j] = k;
} else {
nexts[j] = nexts[k];
}
} else {
k = nexts[k];
}
}
}
int kmp (char *s, char *p) {
int i = 0, j = 0;
int slen = strlen (s);
int plen = strlen (p);
stack<o>O;
while (i < slen) {
if (j == -1 || s[i] == p[j]) {
i++;
j++;
O.push (o (s[i - 1], j) );
} else {
j = nexts[j];
}
if (j == plen) {
int l = plen;
while (l --) O.pop();
if (O.empty()) {
j = 0;
} else {
j = O.top().l;
}
}
}
int cnt = 0;
while(!O.empty()){
L[cnt ++] = O.top().c;
O.pop();
}
for(int i = cnt - 1;i >= 0;i --){
printf("%c", L[i]);
}
printf("\n");
}
int main() {
#ifndef ONLINE_JUDGE
//FIN;
//FOUT;
#endif
IO_Init();
while (~scanf ("%s%s", a, b) ) {
getNextval (a);
kmp (b, a);
}
return 0;
}