제출 #383678

#제출 시각아이디문제언어결과실행 시간메모리
383678wlh_code콤보 (IOI18_combo)C++17
컴파일 에러
0 ms0 KiB
#include "combo.h" using namespace std; string guess_sequence (int N) { string keys = "ABXY"; string s; for (int i = 0; i < 4; ++i) { if (press(keys[i])) { s += keys[i]; keys.erase(keys.begin() + i, 1); break; } } for (int i = 1; i < N; ++i) { for (int j = 0; j < 3; ++j) { if (press(keys[j]) > i) { s += keys[j]; break; } } } return s; }

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:6:20: error: could not convert 'keys.std::__cxx11::basic_string<char>::operator[](((std::__cxx11::basic_string<char>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
    6 |   if (press(keys[i])) {
      |                    ^
      |                    |
      |                    __gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}
combo.cpp:8:34: error: no matching function for call to 'std::__cxx11::basic_string<char>::erase(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >, int)'
    8 |    keys.erase(keys.begin() + i, 1);
      |                                  ^
In file included from /usr/include/c++/10/string:55,
                 from combo.h:3,
                 from combo.cpp:1:
/usr/include/c++/10/bits/basic_string.h:1806:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]'
 1806 |       erase(size_type __pos = 0, size_type __n = npos)
      |       ^~~~~
/usr/include/c++/10/bits/basic_string.h:1806:23: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 1806 |       erase(size_type __pos = 0, size_type __n = npos)
      |             ~~~~~~~~~~^~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:1825:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::__const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator = std::__cxx11::basic_string<char>::iterator; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::__const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 1825 |       erase(__const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/basic_string.h:1825:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/basic_string.h:1844:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::__const_iterator, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::__const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator = std::__cxx11::basic_string<char>::iterator; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::__const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 1844 |       erase(__const_iterator __first, __const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/basic_string.h:1844:56: note:   no known conversion for argument 2 from 'int' to 'std::__cxx11::basic_string<char>::__const_iterator' {aka 'std::__cxx11::basic_string<char>::const_iterator'}
 1844 |       erase(__const_iterator __first, __const_iterator __last)
      |                                       ~~~~~~~~~~~~~~~~~^~~~~~
combo.cpp:14:21: error: could not convert 'keys.std::__cxx11::basic_string<char>::operator[](((std::__cxx11::basic_string<char>::size_type)j))' from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   14 |    if (press(keys[j]) > i) {
      |                     ^
      |                     |
      |                     __gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}