제출 #1356292

#제출 시각아이디문제언어결과실행 시간메모리
1356292hewkawar콤보 (IOI18_combo)C++17
컴파일 에러
0 ms0 KiB
#include "combo.h"

std::string guess_sequence(int N) {
  std::string S = "";

  std::set<char> combo = {'A', 'B', 'X', 'Y'};

  for (int i = 0; i < N; i++) {
    if (i == 0) {
      int ab = press("AB");
      if (ab == 2) {
        S += "AB";
        combo.erase('A');
        i++;
        continue;
      } else if (ab == 1) {
        int a = press("A");

        if (a == 1) {
          S += "A";
          combo.erase('A');
        } else {
          S += "B";
          combo.erase('B');
        }
        continue;
      } else {
        int x = press("X");

        if (x == 1) {
          S += "X";
          combo.erase('X');
        } else {
          S += "Y";
          combo.erase('Y');
        }
        continue;
      }
    } else if (i == N - 1) {
      char d1 = *next(combo.begin(), 0);
      char d2 = *next(combo.begin(), 1);
      char d3 = *next(combo.begin(), 2);

      if (press(S + d1) - S.size() == 1) {
        S += d1;
      } else if (press(S + d2) - S.size() == 1) {
        S += d2;
      } else {
        S += d3;
      }
    } else {
      char d1 = *next(combo.begin(), 0);
      char d2 = *next(combo.begin(), 1);
      char d3 = *next(combo.begin(), 2);

      int ask = press(S + d1 + d1 + S + d1 + d2 + S + d1 + d3 + S + d2);

      if (ask - S.size() == 2) {
        S = S + d1;
      } else if (ask - S.size() == 1) {
        S = S + d2;
      } else {
        S = S + d3;
      }
    }
  }

  return S;
}

컴파일 시 표준 에러 (stderr) 메시지

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:6:8: error: 'set' is not a member of 'std'
    6 |   std::set<char> combo = {'A', 'B', 'X', 'Y'};
      |        ^~~
combo.cpp:2:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    1 | #include "combo.h"
  +++ |+#include <set>
    2 | 
combo.cpp:6:12: error: expected primary-expression before 'char'
    6 |   std::set<char> combo = {'A', 'B', 'X', 'Y'};
      |            ^~~~
combo.cpp:13:9: error: 'combo' was not declared in this scope
   13 |         combo.erase('A');
      |         ^~~~~
combo.cpp:21:11: error: 'combo' was not declared in this scope
   21 |           combo.erase('A');
      |           ^~~~~
combo.cpp:24:11: error: 'combo' was not declared in this scope
   24 |           combo.erase('B');
      |           ^~~~~
combo.cpp:32:11: error: 'combo' was not declared in this scope
   32 |           combo.erase('X');
      |           ^~~~~
combo.cpp:35:11: error: 'combo' was not declared in this scope
   35 |           combo.erase('Y');
      |           ^~~~~
combo.cpp:40:23: error: 'combo' was not declared in this scope
   40 |       char d1 = *next(combo.begin(), 0);
      |                       ^~~~~
combo.cpp:40:18: error: 'next' was not declared in this scope; did you mean 'std::next'?
   40 |       char d1 = *next(combo.begin(), 0);
      |                  ^~~~
      |                  std::next
In file included from /usr/include/c++/13/string:47,
                 from combo.h:3,
                 from combo.cpp:1:
/usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: 'std::next' declared here
  232 |     next(_InputIterator __x, typename
      |     ^~~~
combo.cpp:52:23: error: 'combo' was not declared in this scope
   52 |       char d1 = *next(combo.begin(), 0);
      |                       ^~~~~
combo.cpp:52:18: error: 'next' was not declared in this scope; did you mean 'std::next'?
   52 |       char d1 = *next(combo.begin(), 0);
      |                  ^~~~
      |                  std::next
/usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: 'std::next' declared here
  232 |     next(_InputIterator __x, typename
      |     ^~~~