제출 #127679

#제출 시각아이디문제언어결과실행 시간메모리
127679hcaushi콤보 (IOI18_combo)C++14
컴파일 에러
0 ms0 KiB
/*
    This program tries to find a given combo move in as few guesses as possible.
    It works by testing two passwords at a time and using it to deduce the three possible next passwords it should try.
    It scores full marks in the IOI 2018.
 */

#include <iostream>
using namespace std;

std::string guess_sequence(int N) {

    char[2*N] guess;                                        // The string we're trying
    char[N] suspicion2;
    char not_next_letter;
    char[2] next_letter;
    guess[0] = 'A';
    guess[N] = 'B';

    for (int i=1; i<N; i++) {

        guess[i] = 'B';
        guess[i+N] = 'A';

    }

    char first_letter;                                      // The first letter, if it's confirmed
    int number_correct;                                     // The most recent number of letters we got correct
    int last_correct;                                       // The previous number correct, also the highest number correct we've ever had

    // Begin //
    number_correct = press(guess);

    if (number_correct == 0) {

        guess[0] = 'X';
        guess[N] = 'Y';

        for (int i=1; i<N; i++) {

            guess[i] = 'A';
            guess[i+N] = 'A';

        }

    }

    else {

        for (int i = number_recorded; i < last_correct; i++)
        {

            suspicion2[i] = guess[i+N];
            guess[i+N] = guess[i];

        }

    }

    while (number_correct < N) {

        last_correct = max(number_correct, last_correct);
        number_correct = press(guess);

        not_next_letter = guess[number_correct];

        if ((first_letter == 'A' && not_next_letter == 'B') || (first_letter == 'B' && not_next_letter == 'A')) {
            next_letter = {'X', 'Y'};
        }

        else if ((first_letter == 'A' && not_next_letter == 'X') || (first_letter == 'X' && not_next_letter == 'A')) {
            next_letter = {'B', 'Y'};
        }

        else if ((first_letter == 'A' && not_next_letter == 'Y') || (first_letter == 'Y' && not_next_letter == 'A')) {
            next_letter = {'B', 'X'};
        }

        else if ((first_letter == 'B' && not_next_letter == 'X') || (first_letter == 'X' && not_next_letter == 'B')) {
            next_letter = {'A', 'Y'};
        }

        else if ((first_letter == 'B' && not_next_letter == 'Y') || (first_letter == 'Y' && not_next_letter == 'B')) {
            next_letter = {'A', 'X'};
        }

        else {
            next_letter = {'A', 'B'};
        }

        if (number_correct > last_correct) {

            for (int i = last_correct; i < number_correct; i++) {

                suspicion2[i-1] = guess[i+N-1];
                suspicion2[i] = guess[i+N];

            }

            for (int i = number_correct; i < N; i++) {

                guess[i] = next_letter[0];
                guess[i+N] = next_letter[1];

            }

        }

        else if (number_correct < last_correct) {


            for (int i = last_correct; i < number_correct; i++) {

                guess[i] = suspicion2[i];
                guess[i+N] = suspicion2[i];

            }

            for (int i = number_correct; i < N; i++) {

                guess[i] = next_letter[0];
                guess[i+N] = next_letter[1];

            }

        }

        else {
            // Error //
            return 1
        }

    }

    for (int i=0; i < N; i++) {
        suspicion1[i] = guess[i];
        suspicion2[i] = guess[i+N];
    }

    press(suspicion1) == N ? return suspicion1 : return suspicion2;

}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:12:10: error: expected identifier before numeric constant
   12 |     char[2*N] guess;                                        // The string we're trying
      |          ^
combo.cpp:12:10: error: expected ']' before numeric constant
   12 |     char[2*N] guess;                                        // The string we're trying
      |          ^
      |          ]
combo.cpp:12:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   12 |     char[2*N] guess;                                        // The string we're trying
      |         ^
combo.cpp:12:9: error: structured binding declaration cannot have type 'char'
combo.cpp:12:9: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
combo.cpp:12:9: error: empty structured binding declaration
combo.cpp:12:15: error: expected initializer before 'guess'
   12 |     char[2*N] guess;                                        // The string we're trying
      |               ^~~~~
combo.cpp:13:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   13 |     char[N] suspicion2;
      |         ^
combo.cpp:13:9: error: structured binding declaration cannot have type 'char'
   13 |     char[N] suspicion2;
      |         ^~~
combo.cpp:13:9: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
combo.cpp:13:10: error: declaration of 'auto N' shadows a parameter
   13 |     char[N] suspicion2;
      |          ^
combo.cpp:10:32: note: 'int N' previously declared here
   10 | std::string guess_sequence(int N) {
      |                            ~~~~^
combo.cpp:13:13: error: expected initializer before 'suspicion2'
   13 |     char[N] suspicion2;
      |             ^~~~~~~~~~
combo.cpp:13:13: error: expected ';' before 'suspicion2'
combo.cpp:15:10: error: expected identifier before numeric constant
   15 |     char[2] next_letter;
      |          ^
combo.cpp:15:10: error: expected ']' before numeric constant
   15 |     char[2] next_letter;
      |          ^
      |          ]
combo.cpp:15:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     char[2] next_letter;
      |         ^
combo.cpp:15:9: error: structured binding declaration cannot have type 'char'
combo.cpp:15:9: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
combo.cpp:15:9: error: empty structured binding declaration
combo.cpp:15:13: error: expected initializer before 'next_letter'
   15 |     char[2] next_letter;
      |             ^~~~~~~~~~~
combo.cpp:16:5: error: 'guess' was not declared in this scope
   16 |     guess[0] = 'A';
      |     ^~~~~
combo.cpp:31:22: error: 'press' was not declared in this scope
   31 |     number_correct = press(guess);
      |                      ^~~~~
combo.cpp:49:22: error: 'number_recorded' was not declared in this scope; did you mean 'number_correct'?
   49 |         for (int i = number_recorded; i < last_correct; i++)
      |                      ^~~~~~~~~~~~~~~
      |                      number_correct
combo.cpp:52:13: error: 'suspicion2' was not declared in this scope
   52 |             suspicion2[i] = guess[i+N];
      |             ^~~~~~~~~~
combo.cpp:67:13: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
   67 |             next_letter = {'X', 'Y'};
      |             ^~~~~~~~~~~
      |             first_letter
combo.cpp:71:13: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
   71 |             next_letter = {'B', 'Y'};
      |             ^~~~~~~~~~~
      |             first_letter
combo.cpp:75:13: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
   75 |             next_letter = {'B', 'X'};
      |             ^~~~~~~~~~~
      |             first_letter
combo.cpp:79:13: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
   79 |             next_letter = {'A', 'Y'};
      |             ^~~~~~~~~~~
      |             first_letter
combo.cpp:83:13: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
   83 |             next_letter = {'A', 'X'};
      |             ^~~~~~~~~~~
      |             first_letter
combo.cpp:87:13: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
   87 |             next_letter = {'A', 'B'};
      |             ^~~~~~~~~~~
      |             first_letter
combo.cpp:94:17: error: 'suspicion2' was not declared in this scope
   94 |                 suspicion2[i-1] = guess[i+N-1];
      |                 ^~~~~~~~~~
combo.cpp:101:28: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
  101 |                 guess[i] = next_letter[0];
      |                            ^~~~~~~~~~~
      |                            first_letter
combo.cpp:113:28: error: 'suspicion2' was not declared in this scope
  113 |                 guess[i] = suspicion2[i];
      |                            ^~~~~~~~~~
combo.cpp:120:28: error: 'next_letter' was not declared in this scope; did you mean 'first_letter'?
  120 |                 guess[i] = next_letter[0];
      |                            ^~~~~~~~~~~
      |                            first_letter
combo.cpp:129:20: error: could not convert '1' from 'int' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
  129 |             return 1
      |                    ^
      |                    |
      |                    int
combo.cpp:129:21: error: expected ';' before '}' token
  129 |             return 1
      |                     ^
      |                     ;
  130 |         }
      |         ~            
combo.cpp:135:9: error: 'suspicion1' was not declared in this scope
  135 |         suspicion1[i] = guess[i];
      |         ^~~~~~~~~~
combo.cpp:136:9: error: 'suspicion2' was not declared in this scope
  136 |         suspicion2[i] = guess[i+N];
      |         ^~~~~~~~~~
combo.cpp:139:11: error: 'suspicion1' was not declared in this scope
  139 |     press(suspicion1) == N ? return suspicion1 : return suspicion2;
      |           ^~~~~~~~~~
combo.cpp:139:30: error: expected primary-expression before 'return'
  139 |     press(suspicion1) == N ? return suspicion1 : return suspicion2;
      |                              ^~~~~~
combo.cpp:139:29: error: expected ':' before 'return'
  139 |     press(suspicion1) == N ? return suspicion1 : return suspicion2;
      |                             ^~~~~~~
      |                             :
combo.cpp:139:30: error: expected primary-expression before 'return'
  139 |     press(suspicion1) == N ? return suspicion1 : return suspicion2;
      |                              ^~~~~~
combo.cpp:12:9: warning: unused structured binding declaration [-Wunused-variable]
   12 |     char[2*N] guess;                                        // The string we're trying
      |         ^
combo.cpp:15:9: warning: unused structured binding declaration [-Wunused-variable]
   15 |     char[2] next_letter;
      |         ^