Submission #520396

# Submission time Handle Problem Language Result Execution time Memory
520396 2022-01-29T18:41:38 Z Alex_tz307 Password (RMI18_password) C++17
Compilation error
0 ms 0 KB
struct sir {
  string s;

  sir() : s("") {}

  bool operator < (const sir &a) const {
    return s.size() > a.s.size();
  };
};

int query(string str);

string guess(int n, int m) {
  priority_queue<sir> pq;
  int sum_freq = 0;
  for (int i = 0; i <= m - 1; ++i) {
    char c = i + 97;
    int freq;
    if (i <= m - 2) {
      string aux = "";
      for (int j = 0; j <= n - 1; ++j) {
        aux += c;
      }
      sum_freq += query(aux);
    } else {
      freq = n - sum_freq;
    }
    sir a;
    for (int j = 0; j <= freq - 1; ++j) {
      a.s += c;
    }
    pq.push(a);
  }
  while ((int)pq.size() >= 2) {
    sir a = pq.top();
    pq.pop();
    sir b = pq.top();
    pq.pop();
    sir c;
    while (a.s.empty() == false && b.s.empty() == false) {
      string aux = "";
      aux += c.s;
      aux += a.s[0];
      aux += b.s;
      if (query(aux) == 1 + c.s.size() + b.s.size()) {
        c.s += a.s[0];
        a.s.erase(a.s.begin());
      } else {
        c.s += b.s[0];
        b.s.erase(b.s.begin());
      }
    }
    c.s += a.s;
    c.s += b.s;
    pq.push(c);
  }
  query(pq.top().s);
}

Compilation message

password.cpp:2:3: error: 'string' does not name a type
    2 |   string s;
      |   ^~~~~~
password.cpp: In constructor 'sir::sir()':
password.cpp:4:11: error: class 'sir' does not have any field named 's'
    4 |   sir() : s("") {}
      |           ^
password.cpp: In member function 'bool sir::operator<(const sir&) const':
password.cpp:7:12: error: 's' was not declared in this scope
    7 |     return s.size() > a.s.size();
      |            ^
password.cpp:7:25: error: 'const struct sir' has no member named 's'
    7 |     return s.size() > a.s.size();
      |                         ^
password.cpp: At global scope:
password.cpp:11:11: error: 'string' was not declared in this scope
   11 | int query(string str);
      |           ^~~~~~
password.cpp:13:1: error: 'string' does not name a type
   13 | string guess(int n, int m) {
      | ^~~~~~