제출 #138250

#제출 시각아이디문제언어결과실행 시간메모리
138250Lawliet콤보 (IOI18_combo)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; char buttons[] = {'A' , 'B' , 'X' , 'Y'}; int N; string S; string remain; int getInd(char a) { for(int g = 0 ; g < 4 ; g++) if(buttons[g] == a) return g; } int press(string p) { printf("-> %s\n",p.c_str()); int a; scanf("%d",&a); return a; } void getFirstButton() { if( press("AB") >= 1 ) { if( press("A") == 1 ) S[0] = 'A'; else S[0] = 'B'; } else { if( press("C") == 1 ) S[0] = 'C'; else S[0] = 'D'; } } string guess_sequence(int n) { N = n; getFirstButton(); for(int h = 0 ; h < 4 ; h++) if(buttons[h] != S[0]) remain = remain + buttons[h]; for(int g = 1 ; g < N ; g++) { int cnt = 0; for(int h = 0 ; h < 2 ; h++) { //printf("S = %s\n",S.c_str()); //S.push_back(remain[h]); if(press(S + remain[h]) == S.size() + 1) { S = S + remain[h]; break; } //S.pop_back(); } if(S.size() == g) S = S + remain[2]; } return S; } /*int main() { int nn; scanf("%d",&nn); cout << guess_sequence( nn ) << endl; }*/

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:60:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    if(press(S + remain[h]) == S.size() + 1)
      |       ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
combo.cpp:68:15: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |   if(S.size() == g)
      |      ~~~~~~~~~^~~~
combo.cpp:54:7: warning: unused variable 'cnt' [-Wunused-variable]
   54 |   int cnt = 0;
      |       ^~~
combo.cpp: In function 'int getInd(char)':
combo.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
   16 | }
      | ^
combo.cpp: In function 'int press(std::string)':
combo.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d",&a);
      |  ~~~~~^~~~~~~~~
/usr/bin/ld: /tmp/ccf1KhNA.o: in function `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x0): multiple definition of `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/ccQ546KC.o:combo.cpp:(.text+0x100): first defined here
collect2: error: ld returned 1 exit status