Submission #773279

# Submission time Handle Problem Language Result Execution time Memory
773279 2023-07-04T18:47:46 Z BT21tata Password (RMI18_password) C++17
Compilation error
0 ms 0 KB
struct cmp
{
  bool operator()(const string &a, const string &b)
  {
    return a.size()>b.size();
  }
};

string mrg(string &a, string &b)
{
  string ret;
  int pos1=0, pos2=0;
  while(true)
  {
    if(pos1==a.size() or pos2==b.size()) break;
    string cur=ret;
    cur+=a[pos1];
    for(int i=pos2; i<b.size(); i++)
      cur+=b[i];
    int q=query(cur);
    if(q==pos1+b.size()+1)
      ret+=a[pos1++];
    else ret+=b[pos2++];
  }
  while(pos1<a.size()) ret+=a[pos1++];
  while(pos2<b.size()) ret+=b[pos2++];
  return ret;
}


string guess(int n, int s)
{
  priority_queue<string, vector<string>, cmp>q;
  for(int i=0; i<s; i++)
  {
    string s, sec;
    for(int j=0; j<n; j++)
      s+=(char)(i+'a');
    int ret=query(s);
    if(!ret) continue;
    for(int i=0; i<ret; i++)
      sec+=(char)(i+'a');
    q.push(sec);
  }

  while(q.size()>1)
  {
    string s1=q.top(); q.pop();
    string s2=q.top(); q.pop();
    string merged=mrg(s1, s2);
    q.push(merged);
  }
  return q.top();
}

Compilation message

password.cpp:3:25: error: 'string' does not name a type
    3 |   bool operator()(const string &a, const string &b)
      |                         ^~~~~~
password.cpp:3:42: error: 'string' does not name a type
    3 |   bool operator()(const string &a, const string &b)
      |                                          ^~~~~~
password.cpp: In member function 'bool cmp::operator()(const int&, const int&)':
password.cpp:5:14: error: request for member 'size' in 'a', which is of non-class type 'const int'
    5 |     return a.size()>b.size();
      |              ^~~~
password.cpp:5:23: error: request for member 'size' in 'b', which is of non-class type 'const int'
    5 |     return a.size()>b.size();
      |                       ^~~~
password.cpp: At global scope:
password.cpp:9:1: error: 'string' does not name a type
    9 | string mrg(string &a, string &b)
      | ^~~~~~
password.cpp:31:1: error: 'string' does not name a type
   31 | string guess(int n, int s)
      | ^~~~~~