제출 #107284

#제출 시각아이디문제언어결과실행 시간메모리
107284kyunamkCombo (IOI18_combo)C++14
100 / 100
42 ms640 KiB
#include "combo.h"
#include <iostream>

using namespace std;

static int debug = false;

string guess_sequence(int N) {

  string p = "";
  char *b;
  string prefix ="";
  if ( press("AB") )
  {
  //AB
    if (press("A") ) {
      prefix = "A";
      b="BXY";
    }
    else
    {
      prefix = "B";
      b="AXY";
    }
  }
  else
  {
  //AB
    if (press("X") )
    {
      prefix = "X";
      b="ABY";
    }
    else
    {
      prefix = "Y";
      b="ABX";
    }
  }
  if(debug) cout << b[0] << b[1] << b[2] << endl;
  while ( prefix.length() < N-1 ) {
    int i = 0 ;
    int n = 0;
    string append = prefix;
    append = prefix;
    string s ="";

    s+=prefix;
    s+=b[1];

    for ( i = 0 ; i < 3 ; i++) {
      s+=prefix;
      s+=b[2];
      s+=b[i];
    }

    if(debug) cout << s << " ";
    n = press(s) ;
    if(debug) cout << n << endl;

    prefix += b[n-prefix.length()];
    if(debug) cout << "prefix " << prefix << endl;
  }

  if ( N > 1) {
    if ( press(prefix + b[0] + prefix + b[1]) == N ) {
      if ( press(prefix + b[0]) == N )
        prefix.append(1,b[0]);
      else
        prefix.append(1,b[1]);
    } else
    {
      prefix.append(1,b[2]);
    }
  }
  if(debug) cout << prefix << endl;
  return prefix;
}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:18:9: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   18 |       b="BXY";
      |         ^~~~~
combo.cpp:23:9: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   23 |       b="AXY";
      |         ^~~~~
combo.cpp:32:9: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   32 |       b="ABY";
      |         ^~~~~
combo.cpp:37:9: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   37 |       b="ABX";
      |         ^~~~~
combo.cpp:41:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |   while ( prefix.length() < N-1 ) {
      |           ~~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...