146172025-01-20 20:55:29chucknorrisSzóról szóracpp17Belső hiba
#include <bits/stdc++.h>

using namespace std;

int T;

void solve(){
    ///try to guess sending all letters. order does not matter
    char my_guess[] = "abcde", letters[6];///letters = good letters in any order
    char answer[6], ans[6];///answer = answer from server, ans = solution

    for(int i = 0; i < 5; i++) letters[i] = ans[i] = '\0';
    for(int i = 0; i < 5; i++) ans[i] = '-';///nothing yet

    int nr = 0;///number of good letters found
    for(int i = 1; i <= 5; i++){///make 5 guesses with all letters from a to y (without 'z')
        cout << "? " << my_guess << "\n";
        cin >> answer;
        ///check how many good letters are in my_guess
        for(int j = 0; j < 5; j++){
            if(answer[j] != 'W'){///letter in position i is not white ==> good letter
                letters[nr] = my_guess[j]; nr = nr + 1;
            }
        }
        ///build up the next guess with another 5 letters
        for(int j = 0; j < 5; j++) my_guess[j] = my_guess[j] + 5;
    }

    if(nr < 5){///not found 5 letters, fill with 'z'
        for(int i = nr; i < 5; i++) {
                letters[nr] = 'z'; nr = nr + 1;
        }
    }

    ///try to get the exact position of each letter sending 4 times letter[i]...letter[i]
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 5; j++) my_guess[j] = letters[i];///letters[i] = 5 times
        cout << "? " << my_guess << "\n";
        cin >> answer;
        for(int j = 0; j < 5; j++){
            if(answer[j] == 'G') ans[j] = letters[i];
        }
    }

    ///if there are still unguessed letters ==> letter[4]
    for(int i = 0; i < 5; i++) if(ans[i] == '-') ans[i] = letters[4];
    ans[5] = '\0';

    cout << "! " << ans << "\n";
}

int main(){
    cin >> T;
    while(T--) solve();
    return 0;
}