CCCPaste

Untitled

#include 
#include 
#include 
#include 
using namespace std;
int main() {
    string s, pattern;
    cin >> s >> pattern;
    stack > 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}
 
 
 */