2015 February Bronze 1.Censoring Why My Solution Doesn't Work

Link
Censoring

C++
#include <bits/stdc++.h>
#include <cstddef>
using namespace std;

int main() {
	string p,cen;
    cin >> p >> cen;
    int flag=1;
    long long cenlen=cen.length();
    while (flag)
    {
        flag=0;
        for (long long i=0 ; i<p.length()-cenlen ; i++)
        {
            if (p.substr(i,cenlen)==cen)
            {
                p.replace(i,cenlen,"");
                flag=1;
            }
        }
        
    }
    cout << p;
}

I understand how this works from the solution but I don’t understand why this solution doesn’t work, failing cases 7,9,10,11,14,15. This solution looks for the first occurrence of the censored string and replaces it with a blank, effectively removing it. Then I go back to the start of the string to do it again until no occurrences are left.