Submission #755808

# Submission time Handle Problem Language Result Execution time Memory
755808 2023-06-10T16:19:37 Z vjudge1 Password (RMI18_password) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;


string guess(int n, int s){
    int tab[s];
    //cout <<n<<" "<<s<<endl;
    for (int i = 0; i < s; ++i)
    {
        char x=char(i+'a');
        string t="";
        for (int i = 0; i < n; ++i)
        {
                t.push_back(x);
        }
        tab[i]=query(t);
    }
    int fir=0;
    while(tab[fir]==0) fir++;
    string res="";
    for (int i = 0; i < tab[fir]; ++i)
    {
        char x=char(fir+'a');
        res.push_back(x);
    }
    for (int i = fir+1; i < s; ++i)
    {
        for (int j = 0; j < tab[fir]; ++j)
        {
            int p=res.size();
            for (int k = 0; k < p+1; ++k)
            {
                char x=char(i+'a');
                string cur="";
                //cout << x<<endl;
                for (int i = 0; i <= res.size(); ++i)
                {
                    if (i==k) cur.push_back(x);
                    if (i==res.size()) continue;
                    cur.push_back(res[i]);
                }//cout << cur<<endl;
                if (query(cur)>(int)res.size()){
                    res=cur;
                    break;
                }
            }
        }
    }//cout << res<<endl;
    return res;
}

/*int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
  //ifstream f("password.in");
  cin >> n >> s >> password;
  cout << password<<endl;
  //assert(n && s && !password.empty());
  string answer = guess(n, s);
  cout << answer<<endl;
  if (DEBUG) {
    cout << "Your answer: [" << answer << "]\n";
  }

  if (answer.compare(password)) {
    msg << "Your answer was [" << answer
        << "] which does not match the password [" << password << "].";
    end(0);
  } else {
    msg << "You guessed the password with " << numQueries << " queries.";
    end(1);
  }
    return 0;
}*/

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:17:16: error: 'query' was not declared in this scope
   17 |         tab[i]=query(t);
      |                ^~~~~
password.cpp:37:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                 for (int i = 0; i <= res.size(); ++i)
      |                                 ~~^~~~~~~~~~~~~
password.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                     if (i==res.size()) continue;
      |                         ~^~~~~~~~~~~~
password.cpp:43:21: error: 'query' was not declared in this scope
   43 |                 if (query(cur)>(int)res.size()){
      |                     ^~~~~