Submission #228387

#TimeUsernameProblemLanguageResultExecution timeMemory
228387hhh07Combo (IOI18_combo)C++14
Compilation error
0 ms0 KiB
#include <iostream>
#include <string>
#include <algorithm>
#include "combo.h"

using namespace std;

string guess_sequence(int n){
    string curr = "";
    char x[4];
    x[0] = 'A'; x[1] = 'B'; x[2] = 'X'; x[3] = 'Y';
    if (press("AB") > 0){
        if (press("A") > 0)
            curr += 'A';
        else
            curr += 'B';
    }
    else{
        if (press("X") > 0)
            curr += 'X';
        else
            curr += 'Y';
    }
    for (int i = 0; i < 4; i++)
        if (x[i] == curr[0])
            x[i] = 'Y' + 1;
    sort(x, x + 4);
    while(curr.length() < n){
        if (curr.length() == n - 1){
            if (press(curr + x[0]) == n)
                return curr + x[0];
            if (press(curr + x[1]) == n)
                return curr + x[1];
            return curr + x[2];
        }
        string s = "";
        for (int i = 0; i < 3; i++)
            s += curr + x[0] + x[i];
        s += curr + x[1] + curr[0];
        int res = press(s);
        if (res >= 2)
            curr += x[0];
        else if (res >= 1)
            curr += x[1];
        else
            curr += x[2];
        }
    }
    return curr;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:28:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     while(curr.length() < n){
      |           ~~~~~~~~~~~~~~^~~
combo.cpp:29:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         if (curr.length() == n - 1){
      |             ~~~~~~~~~~~~~~^~~~~~~~
combo.cpp: At global scope:
combo.cpp:49:5: error: expected unqualified-id before 'return'
   49 |     return curr;
      |     ^~~~~~
combo.cpp:50:1: error: expected declaration before '}' token
   50 | }
      | ^
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:9:19: warning: control reaches end of non-void function [-Wreturn-type]
    9 |     string curr = "";
      |                   ^~