123492024-12-12 20:44:55szilSzóról szóracpp17Belső hiba
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t; cin >> t;
	while (t--) {
		stack<char> s;
		stack<char> to_check;
		vector<char> ans(5, 0);
		int done = 0;
		for (int i = 0; i < 26; i++) s.push('a'+i);
		while (done < 5) {
            if ((s.size() == 1 && to_check.empty()) || (s.empty() && to_check.size() == 1)) {
                if (s.size() == 1) {
                    to_check.push(s.top());
                }
                for (int i = 0; i < 5; i++) {
                    if (!ans[i]) ans[i] = to_check.top();
                }
                break;
            }
			if (!to_check.empty()) {
				char q = to_check.top();
				to_check.pop();
				string qry(5, q);
				for (int i = 0; i < 5; i++) {
					if (ans[i] && !s.empty()) {
						qry[i] = s.top(); s.pop();
					}
				}
				cout << "? " << qry << endl;
				string res; cin >> res;
				for (int i = 0; i < 5; i++) {
					if (res[i] == 'G' && qry[i] == q) {
						ans[i] = qry[i];
						done++;
					}
                    if (res[i] != 'W' && qry[i] != q) {
						to_check.push(qry[i]);
					}
				}
			} else {
				string qry;
				while (!s.empty() && qry.size() < 5) {
					qry += s.top();
					s.pop();
				}
				int mx = qry.size();
				while (qry.size() < 5) qry += 'z';
				cout << "? " << qry << endl;
				string res; cin >> res;
				for (int i = 0; i < mx; i++) {
					if (res[i] != 'W') {
						to_check.push(qry[i]);
					}
				}
			}
		}
		cout << "! ";
		for (int i = 0; i < 5; i++) {
			cout << ans[i];
		}
		cout << endl;
	}
}