Language: C++

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



inline bool regex_search(const string &S, const string &T) {
    bool flag = true;  
    for(int i=0; i<S.size(); i++) {
        if(S[i]==T[i]) continue;
        if(i==T.size()) break;
        else {
            flag = false;
            break;
        }
    }
    return flag;
}



int main(){
    string S;
    const string dream = "dream";
    const string dreamer = "dreamer";
    const string erase = "erase";
    const string eraser = "eraser";

    cin >> S;

    /** first filter */
    if(S[0]!='d' && S[0]!='e') cout << "NO" << endl;
    
    /** second filter */
    else if(!regex_search(S, dream) && !regex_search(S, erase)) cout << "NO" << endl;

    /** final filter */
    else {
        while(S.size()!=0) {
            if(regex_search(S, dreamer)) S = replace(S, dreamer, '', true);
            else if(regex_search(S, dream)) S = replace(S, dream, '', true);
            else if(regex_search(S, eraser)) S = replace(S, eraser, '', true);
            else if(regex_search(S, erase)) S = replace(S, erase, '', true);
            else break;
        }
        if(S.size()==0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}

Compiler output:
a.cc:39:66: error: empty character constant
   39 |             if(regex_search(S, dreamer)) S = replace(S, dreamer, '', true);
      |                                                                  ^~
a.cc:40:67: error: empty character constant
   40 |             else if(regex_search(S, dream)) S = replace(S, dream, '', true);
      |                                                                   ^~
a.cc:41:69: error: empty character constant
   41 |             else if(regex_search(S, eraser)) S = replace(S, eraser, '', true);
      |                                                                     ^~
a.cc:42:67: error: empty character constant
   42 |             else if(regex_search(S, erase)) S = replace(S, erase, '', true);
      |                                                                   ^~
a.cc: In function 'int main()':
a.cc:39:53: error: no matching function for call to 'replace(std::string&, const std::string&, char, bool)'
   39 |             if(regex_search(S, dreamer)) S = replace(S, dreamer, '', true);
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4280:5: note: candidate: 'template<class _FIter, class _Tp> void std::replace(_FIter, _FIter, const _Tp&, const _Tp&)'
 4280 |     replace(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note:   template argument deduction/substitution failed:
a.cc:39:53: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'bool')
   39 |             if(regex_search(S, dreamer)) S = replace(S, dreamer, '', true);
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::replace(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&, const _Tp&)'
  174 | replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note:   candidate expects 5 arguments, 4 provided
a.cc:40:56: error: no matching function for call to 'replace(std::string&, const std::string&, char, bool)'
   40 |             else if(regex_search(S, dream)) S = replace(S, dream, '', true);
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note: candidate: 'template<class _FIter, class _Tp> void std::replace(_FIter, _FIter, const _Tp&, const _Tp&)'
 4280 |     replace(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note:   template argument deduction/substitution failed:
a.cc:40:56: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'bool')
   40 |             else if(regex_search(S, dream)) S = replace(S, dream, '', true);
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::replace(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&, const _Tp&)'
  174 | replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note:   candidate expects 5 arguments, 4 provided
a.cc:41:57: error: no matching function for call to 'replace(std::string&, const std::string&, char, bool)'
   41 |             else if(regex_search(S, eraser)) S = replace(S, eraser, '', true);
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note: candidate: 'template<class _FIter, class _Tp> void std::replace(_FIter, _FIter, const _Tp&, const _Tp&)'
 4280 |     replace(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note:   template argument deduction/substitution failed:
a.cc:41:57: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'bool')
   41 |             else if(regex_search(S, eraser)) S = replace(S, eraser, '', true);
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::replace(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&, const _Tp&)'
  174 | replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note:   candidate expects 5 arguments, 4 provided
a.cc:42:56: error: no matching function for call to 'replace(std::string&, const std::string&, char, bool)'
   42 |             else if(regex_search(S, erase)) S = replace(S, erase, '', true);
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note: candidate: 'template<class _FIter, class _Tp> void std::replace(_FIter, _FIter, const _Tp&, const _Tp&)'
 4280 |     replace(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4280:5: note:   template argument deduction/substitution failed:
a.cc:42:56: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'bool')
   42 |             else if(regex_search(S, erase)) S = replace(S, erase, '', true);
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::replace(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&, const _Tp&)'
  174 | replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:174:1: note:   candidate expects 5 arguments, 4 provided