Submission #1118494

# Submission time Handle Problem Language Result Execution time Memory
1118494 2024-11-25T14:59:19 Z somefolk Password (RMI18_password) C++17
Compilation error
0 ms 0 KB
int query(string s);

string guess(int n, int s){
    string sol = "", temp = "";
    for(char i = 'a'; i < 'a'+s; i++){
        string letter = string(n, i);
        int amount = query(letter);
        int initAmount = amount;
        if(amount == 0) continue;
        if(i == 'a'){
            temp += string(amount, i);
        } else {
            int len = temp.length();
            vector<pair<int, int>> add;
            for(int j = 0; j <= len; j++){
                string curr = temp.substr(0, len-j) + string(n-(len-j), i);
                amount = query(curr);
                int pos = len - j;
                int diff = amount - pos;
                if(diff > 0){
                    add.push_back({pos, diff});
                    initAmount -= diff;
                    if(initAmount <= 0) break;
                }
            }
            int k = 0;
            for(auto &j : add){
                temp.insert(j.first + k, string(j.second, i));
                k+=j.second;
                // cout << "{" << j.first << " " << j.second << "}" << endl;
            }

            // cout << "| " << temp << " |" << endl;
        }
    }

    return temp;
}

Compilation message

password.cpp:1:11: error: 'string' was not declared in this scope
    1 | int query(string s);
      |           ^~~~~~
password.cpp:3:1: error: 'string' does not name a type
    3 | string guess(int n, int s){
      | ^~~~~~