Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <stack>
- using namespace std;
- int main() {
- string s, pattern;
- cin >> s >> pattern;
- stack<pair<int, int> > st;
- for(int i = 0; i < s.size(); i++) {
- bool match = false;
- if(s[i] == pattern[0]) {
- st.push({i, 0});
- match = true;
- }
- else if(!st.empty() and s[i] == pattern[st.top().second + 1]) {
- st.top().second++;
- match = true;
- }
- if(!st.empty() and st.top().second == pattern.size() - 1) {
- for(int j = st.top().first; j <= i; j++) {
- s[j] = '*';
- }
- st.pop();
- }
- if(!match) {
- while(!st.empty()) {
- st.pop();
- }
- }
- }
- for(int i = 0; i < s.size(); i++) {
- if(s[i] != '*') {
- cout << s[i];
- }
- }
- cout << endl;
- return 0;
- }
- /*
- B***C4
- BC4
- {0, 1}
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement