Submission #646262

# Submission time Handle Problem Language Result Execution time Memory
646262 2022-09-29T10:43:08 Z Matteo_Verz Password (RMI18_password) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#ifdef BLAT
    #include "debug/debug.hpp"
    #include "password.h"
#else
    #define debug(x...)
#endif

using namespace std;

string mergeStrings(string &a, string &b) {
    string mergedSoFar, queryString;
    while (a.size() || b.size()) {
        if (!a.size()) {
            mergedSoFar += b;
            return mergedSoFar;
        }

        queryString = mergedSoFar + a[0] + b;
        int len = query(queryString);
        
        if (len == queryString.size()) {
            mergedSoFar.push_back(a[0]);
            a.erase(0, 1);
        } else {
            mergedSoFar.push_back(b[0]);
            b.erase(0, 1);
        }
    }

    return mergedSoFar;
}

string guess(int n, int s) {
    string ask;
    vector <string> vs;

    for (char ch = 'a'; ch - 'a' < s; ch++) {
        ask.clear();
        for (int i = 0; i < n; i++)
            ask += ch;
        int len = query(ask);

        ask = "";
        for (int i = 0; i < len; i++)
            ask += ch;
        vs.push_back(ask);
    }

    while (vs.size() > 1) {
        string a = vs.back();
        vs.pop_back();
        string b = vs.back();
        vs.pop_back();

        string c = mergeStrings(a, b);
        vs.push_back(c);
    }

    return vs[0];
}

Compilation message

password.cpp: In function 'std::string mergeStrings(std::string&, std::string&)':
password.cpp:20:19: error: 'query' was not declared in this scope
   20 |         int len = query(queryString);
      |                   ^~~~~
password.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         if (len == queryString.size()) {
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:42:19: error: 'query' was not declared in this scope
   42 |         int len = query(ask);
      |                   ^~~~~