답안 #476229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476229 2021-09-25T13:10:38 Z iulia13 Password (RMI18_password) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 5005;
string ans, prov;
int cnt[N], nn, ss;
string p, password;/*
int query(string q) {


  int len = q.size();

  // validation


  // while possible, advance one character in q and find its next
  // occurrence in password
  int i = 0, j = 0, plen = password.size();
  while (i < plen && j < len) {
    while ((i < plen) && (password[i] != q[j])) {
      i++;
    }
    if (i < plen) {
      i++;
      j++;
    }
  }


  return j;
}*/
string guess(int n, int s)
{
    char a;
    int q = 0;
    for (int i = 0; i < s; i++)
    {
        a = 'a' + i;
        p = ans;
        for (int j = q; j < n; j++)
            p += a;
        for (int h = q; h >= 0; h--)
        {
            cnt[h] = query(p) - h;
            if (h)
                p[h - 1] = a;
        }
        int nq = 0;
        prov = "";
        for (int j = 0; j <= q; j++)
        {
            int x = cnt[j] - cnt[j + 1];
            while(x--)
            {
                prov += a;
                nq++;
            }
            if (j != q)
            {
                prov += ans[j];
                nq++;
            }
        }
        q = nq;
        ans = prov;
    }
    return ans;
}/*
int main()
{
    freopen("x.in", "r", stdin);
    freopen("x.out", "w", stdout);
    int nn, ss;
    cin >> nn >> ss;
    cin >> password;
    cout << guess(nn, ss);
    return 0;
}*/

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:44:22: error: 'query' was not declared in this scope
   44 |             cnt[h] = query(p) - h;
      |                      ^~~~~