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:41: error: empty character constant
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                                         ^~
a.cc:40:44: error: empty character constant
   40 |             else if(regex_search(S, dream, '')) S = replace(S, dream, true);
      |                                            ^~
a.cc:41:45: error: empty character constant
   41 |             else if(regex_search(S, eraser, '')) S = replace(S, eraser, true);
      |                                             ^~
a.cc:42:44: 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:28: error: no matching function for call to 'regex_search(std::string&, const std::string&, char)'
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
                 from a.cc:1:
/usr/include/c++/14/bits/regex.h:2418:5: note: candidate: 'template<class _Bi_iter, class _Alloc, class _Ch_type, class _Rx_traits> bool std::regex_search(_Bi_iter, _Bi_iter, __cxx11::match_results<_BiIter, _Alloc>&, const __cxx11::basic_regex<_CharT, _TraitsT>&, regex_constants::match_flag_type)'
 2418 |     regex_search(_Bi_iter __s, _Bi_iter __e,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2418:5: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/bits/regex.h:2441:5: note: candidate: 'template<class _Bi_iter, class _Ch_type, class _Rx_traits> bool std::regex_search(_Bi_iter, _Bi_iter, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)'
 2441 |     regex_search(_Bi_iter __first, _Bi_iter __last,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2441:5: note:   template argument deduction/substitution failed:
a.cc:39:28: note:   mismatched types 'const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>' and 'char'
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2464:5: note: candidate: 'template<class _Ch_type, class _Alloc, class _Rx_traits> bool std::regex_search(const _Ch_type*, __cxx11::match_results<const _Ch_type*, _Alloc>&, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)'
 2464 |     regex_search(const _Ch_type* __s,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2464:5: note:   template argument deduction/substitution failed:
a.cc:39:28: note:   mismatched types 'const _Ch_type*' and 'std::__cxx11::basic_string<char>'
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2483:5: note: candidate: 'template<class _Ch_type, class _Rx_traits> bool std::regex_search(const _Ch_type*, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)'
 2483 |     regex_search(const _Ch_type* __s,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2483:5: note:   template argument deduction/substitution failed:
a.cc:39:28: note:   mismatched types 'const _Ch_type*' and 'std::__cxx11::basic_string<char>'
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2502:5: note: candidate: 'template<class _Ch_traits, class _String_allocator, class _Ch_type, class _Rx_traits> bool std::regex_search(const __cxx11::basic_string<_Ch_type, _Ch_traits, _Str_allocator>&, const __cxx11::basic_regex<_CharT, _TraitsT>&, regex_constants::match_flag_type)'
 2502 |     regex_search(const basic_string<_Ch_type, _Ch_traits,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2502:5: note:   template argument deduction/substitution failed:
a.cc:39:28: note:   'const std::string' {aka 'const std::__cxx11::basic_string<char>'} is not derived from 'const std::__cxx11::basic_regex<_CharT, _TraitsT>'
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2525:5: note: candidate: 'template<class _Ch_traits, class _Ch_alloc, class _Alloc, class _Ch_type, class _Rx_traits> bool std::regex_search(const __cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&, __cxx11::match_results<typename __cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)'
 2525 |     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2525:5: note:   template argument deduction/substitution failed:
a.cc:39:28: note:   types 'std::__cxx11::match_results<typename std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>' and 'const std::string' {aka 'const std::__cxx11::basic_string<char>'} have incompatible cv-qualifiers
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2540:5: note: candidate: 'template<class _Ch_traits, class _Ch_alloc, class _Alloc, class _Ch_type, class _Rx_traits> bool std::regex_search(const __cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, __cxx11::match_results<typename __cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)' (deleted)
 2540 |     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2540:5: note:   template argument deduction/substitution failed:
a.cc:39:28: note:   types 'std::__cxx11::match_results<typename std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>' and 'const std::string' {aka 'const std::__cxx11::basic_string<char>'} have incompatible cv-qualifiers
   39 |             if(regex_search(S, dreamer, '')) S = replace(S, dreamer, true);
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:6:13: note: candidate: 'bool regex_search(const std::string&, const std::string&)'
    6 | inline bool regex_search(const string &S, const string &T) {
      |             ^~~~~~~~~~~~
a.cc:6:13: note:   candidate expects 2 arguments, 3 provided
a.cc:39:57: error: no matching function for call to 'replace(std::string&, const std::string&, 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:
/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:   candidate expects 4 arguments, 3 provided
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, 3 provided
a.cc:40:33: error: no matching function for call to 'regex_search(std::string&, const std::string&, char)'
   40 |             else if(regex_search(S, dream, '')) S = replace(S, dream, true);
      |                     ~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2418:5: note: candidate: 'template<class _Bi_iter, class _Alloc, class _Ch_type, class _Rx_traits> bool std::regex_search(_Bi_iter, _Bi_iter, __cxx11::match_results<_BiIter, _Alloc>&, const __cxx11::basic_regex<_CharT, _TraitsT>&, regex_constants::match_flag_type)'
 2418 |     regex_search(_Bi_iter __s, _Bi_iter __e,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2418:5: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/bits/regex.h:2441:5: note: candidate: 'template<class _Bi_iter, class _Ch_type, class _Rx_traits> bool std::regex_search(_Bi_iter, _Bi_iter, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)'
 2441 |     regex_search(_Bi_iter __first, _Bi_iter __last,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2441:5: note:   template argument deduction/substitution failed:
a.cc:40:33: note:   mismatched types 'const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>' and 'char'
   40 |             else if(regex_search(S, dream, '')) S = replace(S, dream, true);
      |                     ~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2464:5: note: candidate: 'template<class _Ch_type, class _Alloc, class _Rx_traits> bool std::regex_search(const _Ch_type*, __cxx11::match_results<const _Ch_type*, _Alloc>&, const __cxx11::basic_regex<_Ch_type, _Rx_traits>&, regex_constants::match_flag_type)'
 2464 |     regex_search(const _Ch_type* __s,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2464:5: note:   template argument deduction/substitution failed:
a.cc:40:33: note:   mismatched types 'const _Ch_type*' and 'std::__cxx11::basic_string<char>'
   40 |             else if(regex_search(S, dream, '')) S = replace(S, dream, true);
      |                     ~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2483:5: note: candidate: 'template