Language: C++

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
string res[65],str;
bool check(string &s)
{
    cout<<"? "<<s<<endl;flush(stdout);
    int t;
    cin>>t;
    if(t==s.size())return 1;
    return 0;
}
string merge(int l,int r)
{
    if(l==r)return res[l];
    int mid=(l+r)>>1;
    string t1=merge(l,mid),t2=merge(mid+1,r),ans;
    int j=0;
    for(int i=0;i<t1.size();i++)
    {
        while(j<t2.size())
        {
            ans.pb(t2[j]);
            if(!check(ans)){ans.pop_back();break;}
            j++;
        }
        ans.pb(t1[i]);
    }
    while(j<t2.size())ans.pb(t2[j]),j++;
    return ans;
}
int main()
{
    int cnt=0,t;
    for(int i='A';i<='Z';i++)
    {
        str.clear();
        for(int j=1;j<=128;j++)str.pb(i);
        cout<<"? "<<str<<endl;flush(stdout);
        cin>>t;
        if(t)
        {
            cnt++;
            for(int j=1;j<=t;j++)res[cnt].pb(i);
        }
    }
    for(int i='a';i<='z';i++)
    {
        str.clear();
        for(int j=1;j<=128;j++)str.pb(i);
        cout<<"? "<<str<<endl;flush(stdout);
        cin>>t;
        if(t)
        {
            cnt++;
            for(int j=1;j<=t;j++)res[cnt].pb(i);
        }
    }
    for(int i='0';i<='9';i++)
    {
        str.clear();
        for(int j=1;j<=128;j++)str.pb(i);
        cout<<"? "<<str<<endl;flush(stdout);
        cin>>t;
        if(t)
        {
            cnt++;
            for(int j=1;j<=t;j++)res[cnt].pb(i);
        }
    }
    cout<<"! "<<merge(1,cnt)<<endl;flush(stdout);
    return 0;
}

Compiler output:
a.cc: In function 'bool check(std::string&)':
a.cc:7:30: error: no matching function for call to 'flush(FILE*&)'
    7 |     cout<<"? "<<s<<endl;flush(stdout);
      |                         ~~~~~^~~~~~~~
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/ostream:766:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::flush(basic_ostream<_CharT, _Traits>&)'
  766 |     flush(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~~
/usr/include/c++/14/ostream:766:5: note:   template argument deduction/substitution failed:
a.cc:7:30: note:   mismatched types 'std::basic_ostream<_CharT, _Traits>' and 'FILE*'
    7 |     cout<<"? "<<s<<endl;flush(stdout);
      |                         ~~~~~^~~~~~~~
a.cc: In function 'int main()':
a.cc:39:36: error: no matching function for call to 'flush(FILE*&)'
   39 |         cout<<"? "<<str<<endl;flush(stdout);
      |                               ~~~~~^~~~~~~~
/usr/include/c++/14/ostream:766:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::flush(basic_ostream<_CharT, _Traits>&)'
  766 |     flush(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~~
/usr/include/c++/14/ostream:766:5: note:   template argument deduction/substitution failed:
a.cc:39:36: note:   mismatched types 'std::basic_ostream<_CharT, _Traits>' and 'FILE*'
   39 |         cout<<"? "<<str<<endl;flush(stdout);
      |                               ~~~~~^~~~~~~~
a.cc:51:36: error: no matching function for call to 'flush(FILE*&)'
   51 |         cout<<"? "<<str<<endl;flush(stdout);
      |                               ~~~~~^~~~~~~~
/usr/include/c++/14/ostream:766:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::flush(basic_ostream<_CharT, _Traits>&)'
  766 |     flush(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~~
/usr/include/c++/14/ostream:766:5: note:   template argument deduction/substitution failed:
a.cc:51:36: note:   mismatched types 'std::basic_ostream<_CharT, _Traits>' and 'FILE*'
   51 |         cout<<"? "<<str<<endl;flush(stdout);
      |                               ~~~~~^~~~~~~~
a.cc:63:36: error: no matching function for call to 'flush(FILE*&)'
   63 |         cout<<"? "<<str<<endl;flush(stdout);
      |                               ~~~~~^~~~~~~~
/usr/include/c++/14/ostream:766:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::flush(basic_ostream<_CharT, _Traits>&)'
  766 |     flush(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~~
/usr/include/c++/14/ostream:766:5: note:   template argument deduction/substitution failed:
a.cc:63:36: note:   mismatched types 'std::basic_ostream<_CharT, _Traits>' and 'FILE*'
   63 |         cout<<"? "<<str<<endl;flush(stdout);
      |                               ~~~~~^~~~~~~~
a.cc:71:41: error: no matching function for call to 'flush(FILE*&)'
   71 |     cout<<"! "<<merge(1,cnt)<<endl;flush(stdout);
      |                                    ~~~~~^~~~~~~~
/usr/include/c++/14/ostream:766:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::flush(basic_ostream<_CharT, _Traits>&)'
  766 |     flush(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~~
/usr/include/c++/14/ostream:766:5: note:   template argument deduction/substitution failed:
a.cc:71:41: note:   mismatched types 'std::basic_ostream<_CharT, _Traits>' and 'FILE*'
   71 |     cout<<"! "<<merge(1,cnt)<<endl;flush(stdout);
      |                                    ~~~~~^~~~~~~~